• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

activity-level preferences

N00Bie

Lurker
Hello!

This is my first post here so kindly excuse me if this is in the wrong place.

Ok, this is how I have done the example of "Shared preferences", this is in my helper preferences class:
Code:
  public static final String GAME_PREFERENCES = "GamePrefs";
and this is in one of my activity's classes:
Code:
// Adding data

       SharedPreferences settings = 
         getSharedPreferences(GAME_PREFERENCES, MODE_PRIVATE); 
         SharedPreferences.Editor prefEditor = settings.edit(); 
         prefEditor.putString("lastLaunch", returnTimeAndDateFormatted()); 
         prefEditor.commit();

// Reading
         SharedPreferences settings2 = 
             getSharedPreferences(GAME_PREFERENCES, MODE_PRIVATE);
             if (settings2.contains("lastLaunch") == true) { 
//               System.err.println(settings2.getString("lastLaunch", "Default"));
                 Log.i("LASTLAUNCH", settings2.getString("lastLaunch", "Not LastLaunch value found!"));
             }

The above is for "shared preferences".

How do I do this for non shared, activity only preferences?

I found this code after googling:
Code:
SharedPreferences activityPreferences = this.getPreferences(MODE_PRIVATE);
String lastLaunch = activityPreferences.getString("lastLaunch", "Not Launched");
but if I get it right that is only to get something that has already been set, it does not say how to set it...

I am so damn confused :confused::(
 
Back
Top Bottom