Marshalling a Notification Parcel

时光怂恿深爱的人放手 提交于 2020-01-02 04:31:08

问题


I'm trying to write a Notification object to a File. The best way I could find was to write the object to a parcel, marshall that parcel to get a byte[] and then write it to a file.

Parcel notif = Parcel.obtain();
notification.writeToParcel(notif, 0);
byte[] notifArray = notif.marshall();

I get a Runtime exception when I try to marshall the parcel though: "Tried to marshall a Parcel that contained Binder objects."

Is there a better way of writing Notification objects to file? Else, how do I get this approach to work?


回答1:


The notification contains a live/active binder object. It wasn't built to be used for saving the state (in a byte[]) rather it implements Parcelable for IPC purposes. You should ideally save the necessary fields rather than the object itself.




回答2:


I guess the best way is to store the information from the notification. The value of Binder object cannot be stored because it will be changed.



来源:https://stackoverflow.com/questions/6661268/marshalling-a-notification-parcel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!