Android: How to save an instance of parcelable object?

為{幸葍}努か 提交于 2019-12-05 06:42:42

问题


I am trying to save an instance of StatusBarNotification, so that i could show the notification later to the user. I noticed that StatusBarNotifcation is not Serializable but Parcelable. Is there any way to store the exact instance state in the database so that even if user turns of his phone, the instance object is stored.

I know its not the best practice to store the Parcelable object in database. But I need to do it.

If there is any way i could get the byte array of the instance, I am open for suggetions.

EDIT

I found out today that, if I turn off my android phone with some un-attended notification, when I restart my phone I am still able to see the same notifications. That being said, android is somehow saving the same instance of notification.

Now my question is, how?? And if android does why can't us.


回答1:


I think you cannot save the parcelable object of notification in the database (also not a good practice).




回答2:


Is there any way to store the exact instance state in the database so that even if user turns of his phone, the instance object is stored.

No. In particular, not only do you have no way of persisting the PendingIntents associated with the Notification, but you have no way of recreating them with all the security rules intact. A PendingIntent is tied closely to the app that creates it; you are not the app that created those PendingIntents originally.



来源:https://stackoverflow.com/questions/33920125/android-how-to-save-an-instance-of-parcelable-object

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