6

In my app I start a foreground service and create a notification for it:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
...
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.icon));
...

This throws an exception on one of my users devices like below (a java.lang.RuntimeException: Could not copy bitmap to parcel blob. exception).

My icons do have default dimensions and small sizes, don't know why they make problems on one device.

Does anyone know what the real issue could be? And how I could avoid this issue or gracefully handle this case? Seems to be a memory issue.

Mipmap icon

I have included following icons:

  • mdpi (48x48, 3,51kB)
  • hdpi (72x72, 6,65kB)
  • xhdpi (96x96, 9,08kB)
  • xxhdpi (144x144, 17,2kB)
  • xxxhdpi (192x192, 22,0kB)

Exception

java.lang.RuntimeException: Unable to start service com.my.app.services.OverlayService@ea0edcc with Intent { act=RESUME cmp=com.my.app/.services.OverlayService }: java.lang.RuntimeException: Could not copy bitmap to parcel blob.
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3079)
    at android.app.ActivityThread.access$2200(ActivityThread.java:163)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5585)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.RuntimeException: Could not copy bitmap to parcel blob.
    at android.graphics.Bitmap.nativeWriteToParcel(Native Method)
    at android.graphics.Bitmap.writeToParcel(Bitmap.java:1541)
    at android.graphics.drawable.Icon.writeToParcel(Icon.java:705)
    at android.os.Parcel.writeParcelable(Parcel.java:1437)
    at android.os.Parcel.writeValue(Parcel.java:1343)
    at android.os.Parcel.writeArrayMapInternal(Parcel.java:686)
    at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1330)
    at android.os.Bundle.writeToParcel(Bundle.java:1079)
    at android.os.Parcel.writeBundle(Parcel.java:711)
    at android.app.Notification.writeToParcel(Notification.java:1731)
    at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:701)
    at android.app.NotificationManager.notify(NotificationManager.java:230)
    at android.app.NotificationManager.notify(NotificationManager.java:194)
    at com.my.app.services.BaseOverlayService.a(SourceFile:39)
    at com.my.app.services.BaseOverlayService.a(SourceFile:23)
    at com.my.app.services.OverlayService.onStartCommand(SourceFile:136)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3062)
prom85
  • 16,896
  • 17
  • 122
  • 242
  • I meet the same crash as you. Have you resolved this problem? I find this article analyze this Runtime Exception but I dont find the way solve it. https://blog.csdn.net/u013989732/article/details/78456276 Sorry it's not in English. – TTKatrina Aug 08 '18 at 07:52
  • I'm getting the same errors. It also happens when I start a foreground service with a notification. No solution yet. – Marlon Oct 29 '18 at 13:33
  • Any luck fixing this? – casolorz Mar 04 '19 at 00:25
  • I am also getting this now – allo86 Apr 22 '22 at 18:17
  • Have you tried compressing the bitmap? https://stackoverflow.com/a/12908133/1221011 – Gonki May 12 '22 at 05:42

0 Answers0