Sunday, December 22, 2013

Next, we need to write our preferences class:

Next, we need to write our preferences class:
view sourceprint?
01/** stores the user object in SharedPreferences */
02public class UserPrefs{
03 
04    /** This application's preferences label */
05    private static final String PREFS_NAME = "com.our.package.UserPrefs";
06 
07    /** This application's preferences */
08    private static SharedPreferences settings;
09 
10   /** This application's settings editor*/
11   private static SharedPreferences.Editor editor;
12 
13   /** Constructor takes an android.content.Context argument*/
14   public UserPrefs(Context ctx){
15        if(settings == null){
16           settings = ctx.getSharedPreferences(PREFS_NAME,
17                                               Context.MODE_PRIVATE );
18        }
19       /*
20        * Get a SharedPreferences editor instance.
21        * SharedPreferences ensures that updates are atomic
22        * and non-concurrent
23        */
24        editor = settings.edit();    
25   }
26   //...
27}

No comments:

Post a Comment