Reputation: 116
I am trying to implement session manager in android, where should i implement it in main activity or extend application class, do explain which is better and why
Upvotes: 0
Views: 565
Reputation: 837
If you are using a splash activity for checking the session would be better so from that you could redirect to a main activity with logged in or logged out user
you can write shared preference in an activity or in a application.Either ways it works the same. I prefer using that in an activity or in a singleTon.
Setting values in Preference:
SharedPreferences.Editor editor = getSharedPreferences("ABC", MODE_PRIVATE).edit();
editor.putString("username", "Gibin");
editor.putInt("access_token", "qwertyuiop");
editor.commit();
Retrieve data from preference:
SharedPreferences prefs = getSharedPreferences("ABC", MODE_PRIVATE);
id = prefs.getString("access_token", "");
if (id.equals("")) {
// session is available
}else
//session is not available
Upvotes: 1