in app have 3 activities:
1 activity: starting activity
in manifest:
<activity android:name=".first"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity>
2 activity: login screen activity.
3 activity: activity showing after correct login.
in manifest:
<activity android:name=".third"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.default" /> </intent-filter> </activity>
in 3. activity have button logout. when click logout button. app going activity 2. , after restart (kill app , start again). app started 1. activity. , it's correct.
but when don't click logout button , restart(kill app , start again). app must started 3 activity (user must still logged-in).
probably should manipulate intent flag.
you put key-value pair in sharedpreferences after log in activity 2.
then in activity 1 check if key-value pair exists, if go activity 3, if not go activity 2.
example:
activity2.java (after succesful login)
sharedpreferences sharedpreferences = getsharedpreferences("mypreferences", context.mode_private); editor editor = sharedpreferences.edit(); editor.putstring("user_logged_in", "true"); editor.apply();
activity1.java (when starting)
sharedpreferences sharedpreferences = getsharedpreferences("mypreferences", context.mode_private); string islogged = sharedpreferences.getstring("user_logged_in", "not_logged" if (islogged.equals("true"))){ //user logged in. go activity 3 }else{ //user not logged in. go activity 2 }
also, make sure clear key sharedpreferences when logging out.
here tutorial, might help:
http://www.tutorialspoint.com/android/android_session_management.htm
Comments
Post a Comment