コード例 #1
0
 public static String getUsername() {
   SharedPreferences prefs;
   prefs =
       AppContext.getAppContext()
           .getSharedPreferences(preferencesIdentifier, Context.MODE_PRIVATE);
   String userName = prefs.getString("username", null);
   return userName;
 }
コード例 #2
0
 public static void storeUsername(String username) {
   SharedPreferences.Editor editor;
   editor =
       AppContext.getAppContext()
           .getSharedPreferences(preferencesIdentifier, Context.MODE_PRIVATE)
           .edit();
   editor.putString("username", username);
   editor.apply();
 }
コード例 #3
0
 public static void clearUserSession() {
   SharedPreferences.Editor editor;
   editor =
       AppContext.getAppContext()
           .getSharedPreferences(preferencesIdentifier, Context.MODE_PRIVATE)
           .edit();
   editor.putString("username", null);
   editor.apply();
 }
コード例 #4
0
 public static Boolean shouldDoAutoLogin() {
   SharedPreferences prefs;
   prefs =
       AppContext.getAppContext()
           .getSharedPreferences(preferencesIdentifier, Context.MODE_PRIVATE);
   String userName = prefs.getString("username", null);
   if (userName != null && !userName.isEmpty()) {
     return true;
   }
   return false;
 }