1

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

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

在 sharedpreference 中保存大约 30 个字符串仍然很好吗?

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

4

1 回答 1

0

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

于 2015-11-07T15:59:35.257 回答