Dave Ranjan
Dave Ranjan

Reputation: 2984

Android: How to save an instance of parcelable object?

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.

Upvotes: 1

Views: 1158

Answers (2)

Mayank Thapliyal
Mayank Thapliyal

Reputation: 11

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

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1007276

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.

Upvotes: 4

Related Questions