如activityA代码:
activityB = new ActivtyB(mHandler,CLOSE_SEARCH_MSG);
//新建对像B传递,一个handler和Message,然后在activityB中发送即可触发activityA的方法:
activityB代码:
if (mHandler != null) {
Message msg = new Message();
msg.what = CLOSE_SEARCH_MSG;
mHandler.sendMessage(msg);
}
activityA代码:
private Handler mHandler = new Handler(){
public void handleMessage(Message msg){
switch (msg.what){
case CLOSE_SEARCH_MSG:
//收到消息做相应事件
break;
}
}
};
时间: 2024-11-08 05:01:25