我正在开发一个Android应用程序,其中我有一个与Activity通信的服务。
我有一个Parcelable类,其中包含StatusBarNotification。我用这种方式写了包裹代码:
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeParcelable(mNotification, 0);
}
public static final Parcelable.Creator<NotificationAdapter> CREATOR = new Parcelable.Creator<NotificationAdapter>() {
@Override
public NotificationAdapter createFromParcel(Parcel in) {
return new NotificationAdapter(in);
}
@Override
public NotificationAdapter[] newArray(int size) {
return new NotificationAdapter[size];
}
};
private NotificationAdapter(Parcel in) {
mNotification = StatusBarNotification.CREATOR.createFromParcel(in);
}
但它引起了例外:
java.lang.RuntimeException: Failed to unparcel Bitmap
at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1647)
at android.graphics.Bitmap$1.createFromParcel(Bitmap.java:1637)
at android.widget.RemoteViews$BitmapCache.<init>(RemoteViews.java:1034)
at android.widget.RemoteViews.<init>(RemoteViews.java:2089)
at android.widget.RemoteViews.<init>(RemoteViews.java:2081)
at android.widget.RemoteViews$3.createFromParcel(RemoteViews.java:3227)
at android.widget.RemoteViews$3.createFromParcel(RemoteViews.java:3225)
at android.app.Notification.<init>(Notification.java:1484)
at android.service.notification.StatusBarNotification.<init>(StatusBarNotification.java:83)
at android.service.notification.StatusBarNotification$1.createFromParcel(StatusBarNotification.java:135)
at android.service.notification.StatusBarNotification$1.createFromParcel(StatusBarNotification.java:132)
我做错了吗?有人可以帮我解决这个问题吗? 谢谢:))
答案 0 :(得分:0)
试试这个:
private NotificationAdapter(Parcel in) {
mNotification = in.readParcelable(StatusBarNotification.class.getClassLoader());
}