共享preferences复位时,应用程序是强制关闭或崩溃应用程序、preferences

由网友(天生的傲骨子)分享简介:我已经注意到,我的应用程序的共享preferences完全复位,如果应用程序是力量关闭或由系统由于某种原因死亡。很显然,是的,我应该避免在首位崩溃,但它确实发生了。如果它确实发生,用户不应亏他们所有的设置,存储与preferences其他数据。I have noticed that my app's SharedPr...

我已经注意到,我的应用程序的共享preferences完全复位,如果应用程序是力量关闭或由系统由于某种原因死亡。很显然,是的,我应该避免在首位崩溃,但它确实发生了。如果它确实发生,用户不应亏他们所有的设置,存储与preferences其他数据。

I have noticed that my app's SharedPreferences are completely reset if the app is force closed or is killed by the system for some reason. Obviously, yes, I should avoid having a crash in the first place but it does happen. If it does happen, the user shouldn't loss all of their settings and other data stored with the Preferences.

我发现在谷歌论坛的主题,但他们没能解决它。

I found this thread on Google Groups but they couldn't solve it.

任何人有任何了解为什么或如何出现这种情况,如果有一种方法可以prevent呢?

Anyone have any insight into why or how this happens and if there is a way to prevent it?

另外,仅供参考我已经看到了这对2.1和2.2设备。它会发生的不只是一些人对每次崩溃。

Also, fyi I have seen this on a 2.1 and a 2.2 device. It will happen on every crash, not just some of them.

感谢

推荐答案

经过一番周围挖我终于发现了问题的根源。通过在我的code错误,字符串preference天渐渐保存null键。因此,当它去加载$ P $大跌后pferences有中引起了preferences崩溃和复位的preferences XML文件中的空白。出于某种原因,我没有得到的preference崩溃的堆栈跟踪,初始崩溃的唯一的直接原因。

After some digging around I finally discovered the source of the problem. Through an error in my code, a string preference was getting saved with a null key. So after the crash when it went to load the Preferences there was a blank in the preferences xml file which caused the preferences to crash and be reset. For some reason I was not getting the stack trace of the preference crash, only the immediate cause of the initial crash.

只是为了以防别人多补充一些细节在未来有一个类似的问题:

Just to add some more details in case someone else has a similar problem in the future:

这有preferences保持完好达,并通过力的关闭按钮preSS XML文件。共享preferences然而,被访问的下一次,xml文件被清除,并重新开始。

The xml file that has the preferences stayed intact up to and through the force close button press. The next time the shared preferences were accessed however, the xml file was cleared and started anew.

阅读全文

相关推荐

最新文章