Android: How to save an instance of parcelable obj

2019-04-02 11:56发布

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.

2条回答
走好不送
2楼-- · 2019-04-02 12:29

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

查看更多
一纸荒年 Trace。
3楼-- · 2019-04-02 12:32

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.

查看更多
登录 后发表回答