service和activity怎样通过handler双向通信?
handler = new Handler(handlerThread.getLooper()){@Override
public void handleMessage(Message msg) {
if(msg.what == 0x00){
mActivityMessenger = msg.replyTo;
Message message = this.obtainMessage();
message.what = 0x12;
message.arg2 = 234;
try {
mActivityMessenger.send(message);
} catch (RemoteException e) {
e.printStackTrace();
}
}
这是service中的代码, mActivityMessenger = msg.replyTo;获取activity中的messager 我怎样能让 mActivityMessenger.send(message);可以在其它地方随意使用呢?上面这段程序能够正常发送到activity,但我在其它地方通过 mActivityMessenger.send(message);发送消息就不行,求大神指教