How to keep the session of user login?

后端 未结 2 1805
孤独总比滥情好
孤独总比滥情好 2021-02-04 21:47

I have an app that requires user to register. I\'ve got the app conected to PHP in my server to do the logic of register/login and so, this is not problem at all.

But, I

相关标签:
2条回答
  • 2021-02-04 22:05

    Yeah, preferences would work. In your onCreate():

    mPrefs = PreferenceManager.getDefaultSharedPrefs(this);
    

    And in some function that gets called after the user logs in:

    SharedPreferences.Editor edit = mPrefs.edit();
    edit.putString("app_username", username);
    edit.putInt("app_userid", userId);
    edit.commit();
    
    0 讨论(0)
  • 2021-02-04 22:29

    Use shared preference for this purpose.. try below code....:

    PreferenceManager pm = PreferenceManager.getDefaultSharedPrefs(this);
    SharedPreferences.Editor edit = pm.edit();
    edit.putString("user", username);
    edit.putInt("pwd", password);
    edit.commit();
    
    0 讨论(0)
提交回复
热议问题