android.app.RemoteServiceException: can‘t deliver broadcast

日常报错记录

android.app.RemoteServiceException: can't deliver broadcast 

W BroadcastQueue: Can't deliver broadcast to com.broadcast.test(pid 1769). Crashing it.
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.broadcast.test, PID: 1769
E AndroidRuntime:
android.app.RemoteServiceException: can't deliver broadcast
E AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768)
E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:106)
E AndroidRuntime:     at android.os.Looper.loop(Looper.java:164)
E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:6494)
E AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

(上面是系统的日志,下面一句是我对crash的捕捉日志)

E CrashHandler: ex = android.app.RemoteServiceException: can't deliver broadcast

刚发送异常报错时很惊讶,因为 app已经正常运行了2个月。突然的报错还是很懵的。但是作为研发,报错肯定时代码运行导致,不论有多少个理由,不管是不是代码逻辑引起的。我们都必须找到原因,解除心里的疑惑。不多说,看日志,打断点,一步步跟踪。

最后发现是使用广播broadcast跨进程传输数据导致的。使用broadcast传输intent数据,由于该intent封装的数据来自后端网络,网络数据突然变大,超出了intent的传输大小限制,导致应用crash。

根据调试时保存数据到文件,测试设备传输200k左右的数据就卡死了。

解决方式:使用其他的方式传输大的数据。

1,使用全局变量缓存。broadcast只做通知,告诉被接收者更新数据。

2,SharedPreference存储。

3,文件存储。

猜你喜欢

转载自blog.csdn.net/weixin_42602900/article/details/133749145