注册 登录
编程论坛 Android开发

service和activity怎样通过handler双向通信?

安卓求教 发布于 2019-06-23 13:31, 2126 次点击
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);发送消息就不行,求大神指教
1 回复
#2
w772496502019-07-07 00:24
  message.what = 0x12;
                    message.arg2 = 234;变量
1