Android: 如何保存parcelable对象的实例?
Android: How to save an instance of parcelable object?
我正在尝试保存 StatusBarNotification
的实例,以便稍后向用户显示通知。我注意到 StatusBarNotifcation
不是 Serializable
而是 Parcelable
。有没有什么方法可以在数据库中存储确切的实例状态,这样即使用户关闭他的 phone,实例对象也会被存储。
我知道将 Parcelable
对象存储在数据库中不是最佳做法。但我必须这样做。
如果有任何方法可以获得实例的字节数组,我愿意接受建议。
编辑
我今天发现,如果我关闭我的 android phone 和一些无人值守的通知,当我重新启动我的 phone 我仍然能够看到相同的内容通知。也就是说,android 以某种方式保存了相同的通知实例。
现在我的问题是,如何??如果 android 可以,为什么我们不能。
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.
没有。特别是,您不仅无法持久保存与 Notification
关联的 PendingIntents
,而且您也无法在所有安全规则完好无损的情况下重新创建它们。 PendingIntent
与创建它的应用程序紧密相关;你不是最初创建这些 PendingIntents
的应用程序。
我认为您不能将通知的可打包对象保存在数据库中(这也不是一个好的做法)。
我正在尝试保存 StatusBarNotification
的实例,以便稍后向用户显示通知。我注意到 StatusBarNotifcation
不是 Serializable
而是 Parcelable
。有没有什么方法可以在数据库中存储确切的实例状态,这样即使用户关闭他的 phone,实例对象也会被存储。
我知道将 Parcelable
对象存储在数据库中不是最佳做法。但我必须这样做。
如果有任何方法可以获得实例的字节数组,我愿意接受建议。
编辑
我今天发现,如果我关闭我的 android phone 和一些无人值守的通知,当我重新启动我的 phone 我仍然能够看到相同的内容通知。也就是说,android 以某种方式保存了相同的通知实例。
现在我的问题是,如何??如果 android 可以,为什么我们不能。
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.
没有。特别是,您不仅无法持久保存与 Notification
关联的 PendingIntents
,而且您也无法在所有安全规则完好无损的情况下重新创建它们。 PendingIntent
与创建它的应用程序紧密相关;你不是最初创建这些 PendingIntents
的应用程序。
我认为您不能将通知的可打包对象保存在数据库中(这也不是一个好的做法)。