致命异常:android.app.RemoteServiceException:无法在android.os.Handler.dispatchMessage

时间:2017-10-27 08:55:52

标签: java android broadcastreceiver android-broadcast android-broadcastreceiver

我在我的Android应用程序上使用广播消息(从io.socket我发送广播消息到我的活动页面)。在某些设备上,三星 SM-G950F SM-A520F 我收到错误“Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast”。我在Fabric crashlytics上遇到此错误,但我无法重现此问题。这是我从Fabric获得的日志,

   Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1813)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6776)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

2 个答案:

答案 0 :(得分:5)

我的app遇到了同样的问题,我所做的是使用LocalBroadcastManager而不是上下文。 Android文档还建议使用LocalBroadcastManager发送应用内广播接收器。

//register your receiver like this
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
          new IntentFilter("custom-event-name"));

// unregister  like this
LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);

// broadcastlike this
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

希望这会有所帮助。谢谢! :)

答案 1 :(得分:3)

我在同一时间使用相同的设备经历了完全相同的事情。问题最终与我支持的应用程序有关,但我认为三星推出了某种类型的更新,这些更新开始引发问题。在10月下旬之前,应用程序从未遇到过这个问题。这让我疯了,因为我无法弄清楚哪个广播引发了这个问题。

根据用户反馈,我最终将其缩小并进行了以下更改:

1)我浏览了应用程序并确保用于Intents的所有自定义“操作”字符串都包含应用程序的包名称。

2)我从使用Context :: sendBroadcast()切换到LocalBroadcastManager :: sendBroadcast()。

You can see my full answer on a different post here