Skip to content Skip to sidebar Skip to footer

Android Preferences: Saving In Activity Or Preferenceactivity

I have an Activity which when clicking the menu and a button appearing there, goes to a PreferenceActivity, and then loads three ListPreferences. The ListPreference lets the user c

Solution 1:

Your asking is not very clear because the answers are already in the question...

  1. Datas on PreferenceActivity are saved automatically

  2. You can access to the SharedPreferences like this

    SharedPreferencespref= PreferenceManager.getDefaultSharedPreferences(this);
    Stringvalue= pref.getString("name_of_my_pref", "default_value");
    

Solution 2:

It seems like it shouldn't matter where you write and read those values if they're within sharedPrefs. However if you're having trouble with it why not just call PreferenceActivity with startActivityForResult() in your main Activity, and within onPause() in your PreferenceActivity simply pass the information into a bundle/intent with intent.putExtras() and send it back to your main Activity with setResult(), finish()? Then do whatever you want with them in your main Activity by pulling the data with intent.getExtras()? Sorry if I missed exactly what you were asking but it's not very clear.

Post a Comment for "Android Preferences: Saving In Activity Or Preferenceactivity"