Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.Context;
- import android.content.SharedPreferences;
- import android.preference.PreferenceManager;
- public class User {String username, value;
- Boolean status;
- SharedPreferences sp;
- SharedPreferences.Editor editor;
- public void setUsername(Context context, String username){
- sp = PreferenceManager.getDefaultSharedPreferences(context);
- editor = sp.edit();
- editor.putString("username", username);
- editor.commit();
- }
- public String getUsername(Context context){
- sp = PreferenceManager.getDefaultSharedPreferences(context);
- value = null;
- username = sp.getString("username", value);
- return username;
- }
- public Boolean isLogin(Context context){
- sp = PreferenceManager.getDefaultSharedPreferences(context);
- value = null;
- username = sp.getString("username", value);
- if (username!=null){
- status = true;
- }else {
- status = false;
- }
- return status;
- }
- public void logOut(Context context){
- sp = PreferenceManager.getDefaultSharedPreferences(context);
- editor = sp.edit();
- editor.putString("username", null);
- editor.commit();
- }
- }
Add Comment
Please, Sign In to add comment