Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement authentication using shared preferences in android?

Tags:

android

I am new to Android.my requirement is to implement simple authentication logic for login screen by using sharedpreferences in android. can any one suggest me...?

like image 971
shiva Avatar asked Jun 03 '26 13:06

shiva


1 Answers

To save details after registration of user (when user is created)...

// Get the app's shared preferences
SharedPreferences login_app_preferences =  context.getSharedPreferences("LOGIN_DETAILS", MODE_PRIVATE);

// Update fields
SharedPreferences.Editor editor = login_app_preferences.edit();
editor.putString("email", strEmailOrLoginId);
editor.putString("password", strPassword);
editor.commit(); // Very important

To access it any where in application....

// Get the app's shared preferences
SharedPreferences login_app_preferences = context.getSharedPreferences("LOGIN_DETAILS", MODE_PRIVATE);

strUserName = login_app_preferences.getString("email", "");
strPassword = login_app_preferences.getString("password", "");
like image 59
Vaibhav Jani Avatar answered Jun 06 '26 05:06

Vaibhav Jani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!