Sunday, 22 December 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}

1 comment:

  1. Hey, I am impressed with your informative words. You are really a great and intelligent writer. I found that this blog post will help me to know more about dating app development. Thanks for sharing! Custom Mobile App Development.

    ReplyDelete