Android应用偏好设置会自动清除 [英] Android app preferences are being cleared automatically

查看:329
本文介绍了Android应用偏好设置会自动清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

突然之间,每次我启动我的应用程序时,都会清除我的用户首选项.我没有在Activity中直接使用首选项,而是在我的Application对象中有一个帮助器类,该类访问这样的首选项:

All of a sudden, each time I start my app, my user preferences are being cleared out. Instead of using preferences directly in an Activity, I have a helper class in my Application object, that accesses preferences like this:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

直到现在,它一直运行良好.我有一个自定义应用程序类,用于管理应用程序的大多数内容,以避免在创建/销毁活动时重新生成此内容的问题.

This has worked perfectly, until just now. I have a custom application class that manages most of the content of the application, to avoid issues of re-generating this content when activites are created/destroyed.

我确实意识到有一种方法可以清除用户的首选项,但是我的代码中没有任何方法.当我开始使用Proguard进行发行版本构建时,似乎确实开始发生这种情况,但现在调试版本中也发生了这种情况.从Eclipse重新下载新的应用程序,甚至只是重新启动该应用程序都会导致首选项被清除.

I do realize there is a way to clear out the user preferences, but I do not have that in my code anywhere. This did seem to start happening when I started building with Proguard for release builds, but this is now happening with debug builds as well. Re-downloading a new app from Eclipse, or even just re-starting the app causes the preferences to be wiped out.

我一直在经历最近的代码更改,但没有发现任何相关的内容.当我即将在市场上发布该应用程序时,我会在调试和测试之间进行切换.发布,但我认为这不会引起这样的问题.

I've been going through my recent code changes, and haven't found anything related. As I'm nearing posting the app on the market, I keep switching between debug & release, but I wouldn't think this would cause a problem like this.

有什么想法吗?

-凯文

推荐答案

已解决.使用Logcat,我终于在读取首选项时注意到了一个异常.我用空键编写了一个新的首选项,这导致了首选项加载异常.我这是愚蠢的错误.

Solved it. With Logcat, I finally noticed an exception when reading preferences. I was writing a new preference with a null key, and it was causing the preference load exception. Dumb mistake on my part.

这篇关于Android应用偏好设置会自动清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆