如何包裹StatusBarNotification
How to parcel StatusBarNotification
我正在开发一个 Android 应用程序,其中有一个服务与 Activity 进行通信。
我有一个 Parcelable class,里面有一个 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.createFromParcel(Bitmap.java:1647)
at android.graphics.Bitmap.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.createFromParcel(RemoteViews.java:3227)
at android.widget.RemoteViews.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.createFromParcel(StatusBarNotification.java:135)
at android.service.notification.StatusBarNotification.createFromParcel(StatusBarNotification.java:132)
我做错了吗?有人可以帮我解决这个问题吗?
谢谢:)
试试这个:
private NotificationAdapter(Parcel in) {
mNotification = in.readParcelable(StatusBarNotification.class.getClassLoader());
}
我正在开发一个 Android 应用程序,其中有一个服务与 Activity 进行通信。
我有一个 Parcelable class,里面有一个 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.createFromParcel(Bitmap.java:1647)
at android.graphics.Bitmap.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.createFromParcel(RemoteViews.java:3227)
at android.widget.RemoteViews.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.createFromParcel(StatusBarNotification.java:135)
at android.service.notification.StatusBarNotification.createFromParcel(StatusBarNotification.java:132)
我做错了吗?有人可以帮我解决这个问题吗? 谢谢:)
试试这个:
private NotificationAdapter(Parcel in) {
mNotification = in.readParcelable(StatusBarNotification.class.getClassLoader());
}