Tutorial 11 -Shared Preferences

 


This is Sample Project Which you can improve UI design & Coding skills .


LoginActivity

SharedPreferences sharedPreferences;

private static final String SHARED_PREF_NAME = "mypref";
private static final String KEY_NAME = "email";

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(KEY_NAME,mEmail.getText().toString());
editor.apply();

String email = sharedPreferences.getString(KEY_NAME,null);

if (email != null){
Intent intent = new Intent(LoginActivity.this,HomeActivity.class);
startActivity(intent);
}



HomeActivity

SharedPreferences sharedPreferences;

private static final String SHARED_PREF_NAME = "mypref";
private static final String KEY_NAME = "email";


sharedPreferences = getSharedPreferences(SHARED_PREF_NAME,MODE_PRIVATE);

String email = sharedPreferences.getString(KEY_NAME,null);



Logoutbutton

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.commit();



















Post a Comment

0 Comments

Youtube Channel Image
Coding With Chathura Subscribe To watch more Project Tutorials
Subscribe
Do you have any doubts? chat with us on WhatsApp
Hello, How can I help you? ...
Click me to start the chat...

Welcome to freesourcecodelk

X