如何永久存储parcelable自定义对象? [英] How to permanently store parcelable custom object?
本文介绍了如何永久存储parcelable自定义对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要储存一个自定义对象(我们称之为myObject的)永久,这样如果是从内存中删除,我可以在我的活动/片段,当应用程序再次启动重新装入onResume()方法。
I want to store a custom object (let's call it MyObject) permanently so that if it is deleted from memory, I can reload it in my activity/fragment onResume() method when the app starts again.
我怎么能这样做?共享preferences似乎不具有用于存储parcelable对象的方法
How can I do that? SharedPreferences doesn't seem to have a method for storing parcelable objects.
推荐答案
您可以写你的捆绑
作为一个包裹到磁盘,然后拿到包裹
后,使用 Parcel.readBundle()
的方法来让你的捆绑
返回。
You can write your Bundle
as a parcel to disk, then get the Parcel
later and use the Parcel.readBundle()
method to get your Bundle
back.
这篇关于如何永久存储parcelable自定义对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文