Results from a preferences page


Last Updated:

  1. Leolicos

    Leolicos Well-Known Member This Topic's Starter

    Joined:
    Jun 16, 2010
    Messages:
    54
    Likes Received:
    0
    How do I get the results of a preferences page? I have the main application page, then when menu > preferences is clicked, a new Activity is started and goes to the preferences page. How do I, when returning to the main application page, grab the values from the preferences page? Likewise, how do I, when going TO the preferences page, set the values according to what they were previously set at?
     

    Advertisement
  2. tdieckman

    tdieckman Well-Known Member

    Joined:
    Sep 30, 2009
    Messages:
    49
    Likes Received:
    5
    When you set up the Activity derived from a PreferenceActivity, it automatically loads and saves values from the default shared preferences--you don't have to do anything.

    To read the values, create a SharedPreferences object:
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    If you want to programmatically set values in SharedPreferences somewhere else in your app, you create a SharedPreferences.Editor object:

    SharedPreferences.Editor edit = preferences.edit();

    Then set values in the object. The changes won't be written out until you call commit() on the SharedPreferences.Editor object.
     
    Leolicos likes this.

Share This Page

Loading...