简体   繁体   中英

Android - preferences not saving when app is killed and restarted?

My apps preferences aren't getting saved when the app gets killed or phone gets restarted. In fact even the back button was resetting the preferences for some reason (until I implemented the @Override onBackPressed with the ACTION_MAIN intent).

Here's the XML for one of the preferences that doesn't get saved:

[ListPreference android:key="Button2" android:title="Button2 action" android:summary="Default Settings: ..." android:entries="@array/action_options" android:entryValues="@array/action_values" android:dialogTitle="Choose your preferred action" android:defaultValue="some value" /]

(I changed the <> tags for [] to display in the question)

I'm using a bunch of list preferences like these in a PreferenceActivity, calling addPreferencesFromResource(R.xml.preferences); in case that's relevant. To be honest I'm working with someone else's code so I'm not too sure what's relevant, so I'll update the question with whatever code snippets people would like to see that may help fix the problem.

Thanks a bunch.

Are you doing something in onStop() or onDestroy()? Sometimes these don't get called. If this is the case add your code to onPause().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM