android 利用Handler触发另一个activity方法

如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;
}
}
};

posted @ 2015-06-02 10:04  jenson138  阅读(2853)  评论(0编辑  收藏  举报