且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android在片段和服务之间发送消息

更新时间:2023-02-26 21:27:00

原来,我的原始问题"的编辑"中的代码有效,但是我必须重新整理一下一些代码:

It turns out that the code in the Edit of my original question works, but I have to shuffle around some of my code:

Bundle extras = intent.getExtras();
messageHandler = (Messenger) extras.get("MESSENGER");

以上内容需要移到SensorServiceonStartCommand中,而不是放在BroadcastReceiver

The above needs to be moved to onStartCommand of SensorService instead of being in the BroadcastReceiver