Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
937 views
in Technique[技术] by (71.8m points)

java - Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast at android.os.Handler.dispatchMessage

I am using broadcast messages on my android application (From io.socket I am sending broadcast messages to my Activity page). On some devices Samsung SM-G950F and SM-A520F I got an error "Fatal Exception: android.app.RemoteServiceException: can't deliver broadcast". I got this error on Fabric crashlytics also I was not able to reproduce this issue. Here is the log I got from 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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was facing the same issue with my app, what I do is use LocalBroadcastManager instead of context. Android documents also suggest using LocalBroadcastManager for sending in-app broadcast receivers.

//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);

Hope this will help. Thanks! :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...