Android:如何保存parcelable对象的实例? [英] Android: How to save an instance of parcelable object?

查看:146
本文介绍了Android:如何保存parcelable对象的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存 StatusBarNotification 的实例,以便稍后我可以向用户显示通知。我注意到 StatusBarNotifcation 不是 Serializable 但是 Parcelable 。有没有办法在数据库中存储确切的实例状态,这样即使用户关闭了他的手机,也会存储实例对象。

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.

我知道在数据库中存储 Parcelable 对象不是最好的做法。但是我需要这样做。

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.

编辑

我今天发现,如果我通过一些未参加的通知关闭我的Android手机,当我重新启动手机时,我仍然可以看到相同的通知。话虽这么说,android以某种方式保存了相同的通知实例。

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.

现在我的问题是,如何?如果android为什么不能我们。

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

推荐答案

我认为你无法在数据库中保存通知的可分配对象(也是不是一个好习惯。)

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

这篇关于Android:如何保存parcelable对象的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆