在我的应用程序中,我启动前台服务并为其创建通知:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId);
...
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.icon));
...
这会在我的一个用户设备上引发异常(例如java.lang.RuntimeException: Could not copy bitmap to parcel blob.
例外)。
我的图标确实有默认尺寸和小尺寸,不知道为什么他们会在一台设备上出现问题。
有谁知道真正的问题是什么?我怎么能避免这个问题或优雅地处理这个案子?似乎是一个记忆问题。
Mipmap图标
我已经包含以下图标:
异常
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)