致命异常:android.app.RemoteServiceException:无法在android.os.Handler.dispatchMessage上传递广播

SHI*_*T.S 18 java android broadcastreceiver android-broadcast android-broadcastreceiver

我在我的Android应用程序上使用广播消息(从io.socket我发送广播消息到我的活动页面).在某些设备上,三星SM-G950FSM-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)
Run Code Online (Sandbox Code Playgroud)

Ash*_*esh 7

我的应用程序遇到了同样的问题,我所做的是使用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);
Run Code Online (Sandbox Code Playgroud)

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

  • 我什至没有使用 LocalBroadcastManager,但最近却收到此错误。不过,错误非常罕见。到目前为止只发生过一次,在运行 Android 9 的 OnePlus 5T 上……还有其他想法为什么会发生这种情况吗? (5认同)
  • @Kamwave 不知道为什么会发生。我只是选择忽略它,就像我见过的其他非常罕见的奇怪案例一样。我认为一般来说,如果您发现仅支持中文的设备出现问题,您可以忽略它们,因为您几乎无能为力。请参阅此处:https://dontkillmyapp.com/ 和此处:https://issuetracker.google.com/issues/122098785 。另请考虑为此问题加注星标。中国制造商毁掉了应用程序(他们默认这样做),这真的很糟糕。 (3认同)
  • 我只在 Google Play Console 中使用运行 Android 13 的 Google Pixel 5 时遇到过此崩溃。不确定它是真实用户还是 Play 发布前报告中的设备。 (2认同)

小智 5

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

根据用户的反馈,我最终缩小了范围并做了以下更改:

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

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

您可以在此处查看我在另一篇文章中的完整答案