开发者

how to implement authentication using shared preferences in android?

开发者 https://www.devze.com 2023-03-03 16:40 出处:网络
I am new to Android.my requirement is to implement simple authentication logic for login screen by using sharedpreferences in 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 m开发者_开发知识库e...?


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", "");
0

精彩评论

暂无评论...
验证码 换一张
取 消