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 want to keep a session of the user in local, so the user doesn't have to login again every time he runs the app.
So, I want something like this:
I only need to store an ID and a Username (both fetched from the DB in the login php method). What's the best way to do this??
I've thought about doing a custom preference, store the data in files or even a local DB (sqlite). Any suggestions?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With