I\'m trying to create an app which uses username and password to login, then stay logged in as long as user didn\'t logout -or didn\'t delete app data of course-, and as far
What you have done is the right, the only thing is you have not committed your preference values.
So your function will look like this
public void doLogin(String username, String password) {
Intent loginIntent = new Intent(LoginActivity.this, HomeActivity.class);
SharedPreferences.Editor editor = perf.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.apply(); //This line will make necessary changes in SharedPreferences file
startActivity(loginIntent);
finish();
}
add the same line on button_logout click
Moreover, I will recommend you to create a utility class for SharedPreference operations.