I want to store Register and Login information in shared preferences in android

后端 未结 1 1147
我寻月下人不归
我寻月下人不归 2021-01-25 17:35

I know there are n number of examples in android for shared preferences but I want to Register and store the info in shared preferences and in database using JSON. And then fetc

1条回答
  •  不思量自难忘°
    2021-01-25 17:51

    At the time of login successfull put this code:

    prefs = getSharedPreferences("logindetail", 0);
                            SharedPreferences.Editor edit = prefs.edit();
                            edit.putString("userLoginStatus", "yes");
                            edit.commit();
    

    At the time of logout use this:

    prefs = getSharedPreferences("logindetail", 0);
    SharedPreferences.Editor edit = prefs.edit();
                                    edit.clear();
                                    edit.commit();
    

    And at the time of checking if user is login or not use below code:

     Loginprefs = getApplicationContext().getSharedPreferences("logindetail", 0);
                userLoginStatus = Loginprefs.getString("userLoginStatus", null);
    if(userLoginStatus.tostring().equals("yes")){
        //the user is login
    }else{
        //user is logout
    }
    

    Hope this helps you

    0 讨论(0)
提交回复
热议问题