This is sample of code from my project , follow these step :
- Create function that will store the data
// Call this function where you want to save your data
private void storeCredentials(String email , String password) {
SharedPreferences credentialsPrefs = getSharedPreferences("prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = credentialsPrefs.edit();
editor.putString("email",email);
editor.putString("password",password);
editor.apply();
}
- Then Call your preferences where you have your edittexts to set data
SharedPreferences credentialsPrefs = getSharedPreferences("prefs", Context.MODE_PRIVATE);
String email = credentialsPrefs.getString("email","default-value");
String password = credentialsPrefs.getString("password","default- value");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…