Home » Android » java – android.app.RemoteServiceException: at android.app.ActivityThread$H.handleMessage when sending notifications

java – android.app.RemoteServiceException: at android.app.ActivityThread$H.handleMessage when sending notifications

Posted by: admin May 14, 2020 Leave a comment


I use a service to display notifications. On some rare devices (3 users among 50 000 every day), I have the the following crash (which can be seen in the Google Play developer console ; only on Android 4.x devices) :

  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509)
  at android.os.Handler.dispatchMessage(Handler.java:110)
  at android.os.Looper.loop(Looper.java:193)
  at android.app.ActivityThread.main(ActivityThread.java:5327)
  at java.lang.reflect.Method.invokeNative(Native Method:0)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
  at dalvik.system.NativeStart.main(Native Method:0)

My notifications are made with a code like this (old style notifs, deprecated in Android 6+ but works anyway ; the bug is on Android 4.x where the code is not deprecated):

Notification notification = new Notification(icon, "Custom Notification", when);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.notifWeatherImageView, WeatherRowTools.getImageForWeatherCode(weatherCodeString));

....some stuff here...

notification.contentView = contentView;
notification.contentIntent = contentIntent;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = 0;
mNotificationManager.notify(1, notification);

Any idea on how to solve this issue?

Thanks a lot !!!

How to&Answers:

I saw similar issues in my builds – Only Kitkat Devices are throwing these in large numbers – Android OS version: 4.4.4, 4.4.2, 4.2.2, 4.0.4

We fixed a similar issue by changing the drawable used by Notification .

.addAction(R.drawable.ic_forward_black_24dp, VIEW_ACTION, pendingIntentView);

We stopped using Vector Assets and started using Image Assets.

R.drawable.ic_forward_black_24dp no longer uses xml file (Vector Asset) and instead we now use png file (Image Asset).


Check this. Even if you’re not using the same SDK as in the linked answer, your problem might still have the same reason.