问题描述
我正在尝试将Notification对象写入文件.我能找到的最好方法是将对象写入一个包裹,将其封送以获取字节[],然后将其写入文件.
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."
是否有更好的方法将Notification对象写入文件?否则,我该如何使用这种方法?
Is there a better way of writing Notification objects to file? Else, how do I get this approach to work?
推荐答案
该通知包含一个活动/活动活页夹对象.它不是为了用于保存状态(以byte []形式)而是为了IPC的目的而实现了Parcelable.理想情况下,您应该保存必要的字段,而不是对象本身.
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.
这篇关于整理通知包裹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!