在SharedPreferences中保存大约30个字符串数据,它显示java.lang.OutOfMemoryErro



我想在我的android应用程序中保存大约30个字符串数据,但有时在内存几乎满的android手机中,会出现以下错误:

致命异常:java.lang.OutOfMemoryError网址:com.android.internal.util.FastXmlSerializer。(FastXmlSerializer.java)网址:com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:177)在android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:596)在android.app.SharedPreferencesImpl.access$800(SharedPreferencesImpl.java:52)在android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:511)在android.app.SharedPreferencesImpl.enqueeDiskWrite(SharedPreferences sImpl.java:532)在android.app.SharedPreferencesImpl.access$100(SharedPreferenencesImpl.java:52)在android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:454)

在共享引用中保存大约30个字符串仍然好吗?

我从这里读到,不为每个更改创建一个新的编辑器,也许我必须为一些调用新编辑器的字符串更改进行更改,这对防止java.lang.OutOfMemoryError有很大贡献吗?或者我必须做其他事情?

您不能在SharedPrefrences中存储大量数据。根据您的移动设备,您可以存储1~2MB甚至更少的空间。如果您需要存储大量数据,那么使用sqlLite数据库是安全的。有几个简单的sqlLite库,如http://satyan.github.io/sugar/

最新更新