简体   繁体   English

如何将SharedPreferences存储到文件中?

[英]How to store SharedPreferences into file?

I have been developing Android application which should have following function: it should store some data between Application executings; 我正在开发具有以下功能的Android应用程序:应在应用程序执行之间存储一些数据; also if I delete application and re-install it app should restore values of data. 另外,如果我删除应用程序并重新安装它,则应用程序应恢复数据值。 I knew that I can store data into SharedPreferences (for working with data in my program) and serialize into file in onDestroy() event. 我知道我可以将数据存储到SharedPreferences中(用于在程序中使用数据),并在onDestroy()事件中序列化为文件。 But SharedPreferences is Non-Serializable class and I can't use it. 但是SharedPreferences是Non-Serializable类,我不能使用它。 Please, suggest me another way for my task, or tell me how I can serialize SharedPreferences. 请为我建议另一种执行任务的方法,或者告诉我如何序列化SharedPreferences。 I know that I can just write important data into simple file but may be there is another means for my problem? 我知道我可以将重要数据写到简单文件中,但是可能还有其他方法可以解决我的问题吗? Thank you 谢谢

You're not going to be able to store data locally after you delete an app, except if you put the data on the SD card, but at that point everyone can read/write/delete it. 删除应用程序后,您将无法在本地存储数据,除非您将数据放在SD卡上,但那时每个人都可以读取/写入/删除它。

Check this out for more information on data storage: 签出有关数据存储的更多信息:

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Usually you would store your settings in an SQLITE db or in some sort of http://developer.android.com/reference/java/util/Properties.html 通常,您会将设置存储在SQLITE数据库中,或存储在某种http://developer.android.com/reference/java/util/Properties.html中

Cheers 干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM