1

I'm a very beginner in Android development. I got a problem here, For example :
user1 register successfully then he click on btnLogin to login the first time . then Activity1,Activity2 display to let user1 insert his detail information. then user1 logout while user1's information is saved in somewhere. then user1 login the second time, in this second time, Activity1,Activity2 are not displayed but directly go on MainActivity.

user2 register successfully then he click on btnLogin to login the first time . then Activity1,Activity2 display to let user2 insert his detail information. then user2 logout while user2's information is saved in somewhere. then user2 login the second time, on that time, Activity1,Activity2 are not displayed but directly go on MainActivity.
I want to apply this user's session management for any user who login and logout from my app, but I don't know how exactly step by step to implement it. please help me :(

Việt Dũng Lê
  • 303
  • 1
  • 4
  • 10
  • Check this link out. May help you http://stackoverflow.com/questions/9370293/add-a-remember-me-checkbox – Andrew Nguyen Nov 25 '16 at 17:37
  • thanks for reply but main problem is how to display two specified Activity when the user first time login to my app :) . saving their information is sub problem :) – Việt Dũng Lê Nov 25 '16 at 17:41

1 Answers1

0

You can use SharedPreferences. For sample :

In first activity check is first login with:

SharedPreferences preferences=getSharedPreferences("packagename", getApplicationContext().MODE_PRIVATE);
String firstLogin=preferences.putBoolean("firstLogin",false); // default value is false;

After first login save status with :

SharedPreferences preferences = getSharedPreferences("packagename", getApplicationContext().MODE_PRIVATE);
Editor editor = preferences.edit();
editor.putBoolean("firstLogin", true);
editor.commit();
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98