Advertisement
rachmadi

User.java

Mar 11th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import android.content.Context;
  2. import android.content.SharedPreferences;
  3. import android.preference.PreferenceManager;
  4.  
  5. public class User {String username, value;
  6.     Boolean status;
  7.     SharedPreferences sp;
  8.     SharedPreferences.Editor editor;
  9.  
  10.     public void setUsername(Context context, String username){
  11.         sp = PreferenceManager.getDefaultSharedPreferences(context);
  12.         editor = sp.edit();
  13.         editor.putString("username", username);
  14.         editor.commit();
  15.     }
  16.  
  17.     public String getUsername(Context context){
  18.         sp = PreferenceManager.getDefaultSharedPreferences(context);
  19.         value = null;
  20.         username = sp.getString("username", value);
  21.         return username;
  22.     }
  23.  
  24.     public Boolean isLogin(Context context){
  25.         sp = PreferenceManager.getDefaultSharedPreferences(context);
  26.         value = null;
  27.         username = sp.getString("username", value);
  28.         if (username!=null){
  29.             status = true;
  30.         }else {
  31.             status = false;
  32.         }
  33.         return status;
  34.     }
  35.  
  36.     public void logOut(Context context){
  37.         sp = PreferenceManager.getDefaultSharedPreferences(context);
  38.         editor = sp.edit();
  39.         editor.putString("username", null);
  40.         editor.commit();
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement