开发者

Android app preferences are being cleared automatically

开发者 https://www.devze.com 2023-02-06 12:57 出处:网络
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

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.

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.

Any ideas?

-Kev开发者_JAVA技巧in


To quote you...

This did seem to start happening when I started building with Proguard for release builds

Since release builds and debug builds use different keys for signing, they can't coexist on the same device. Are you sure you aren't uninstalling your debug build when you install your release build? Uninstalls will nuke any preferences tied to the app.

Since you say you have no code that would erase preferences, the only other way I know of for preferences to go away is if the physical preferences XML file gets cleared or deleted. So, you might check to make sure you don't have any code that clears out files in your application local storage area.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号