Guest User

Untitled

a guest
Jan 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public static final String PREFS_NAME = "MyPrefsFile";
  2. private static final String PREF_USERNAME = "username";
  3. private static final String PREF_PASSWORD = "password";
  4.  
  5. getSharedPreferences(PREFS_NAME,MODE_PRIVATE)
  6. .edit()
  7. .putString(PREF_USERNAME, username)
  8. .putString(PREF_PASSWORD, password)
  9. .commit();
  10.  
  11. SharedPreferences pref = getSharedPreferences(PREFS_NAME,MODE_PRIVATE);
  12. String username = pref.getString(PREF_USERNAME, null);
  13. String password = pref.getString(PREF_PASSWORD, null);
  14.  
  15. if (username == null || password == null) {
  16. //Prompt for username and password
  17. }
  18.  
  19.  
  20. Alternatively, if you don't want to name a preferences file you can just use the default:
  21.  
  22.  
  23. SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
Add Comment
Please, Sign In to add comment