Even After going through several questions , it is bit confusing what to do when a user logs out of application. What should be done when ideally in this situation? How to exit app?
-
1Android apps aren't designed to ever quit the application. You can do it, but its not recommended practice as the UI lifecycle will handle all of that for you. Do you have a specific reason why you nees to exit your app conpletely? There are multitudes of questions about this on SO. Have a search :) – laminatefish Jun 14 '13 at 07:38
-
Go through my answer http://stackoverflow.com/questions/3226495/android-exit-application-code/9735524#9735524 – Kartik Domadiya Jun 14 '13 at 07:39
-
1[this](http://stackoverflow.com/a/11643260/1265724) may be helpful – Ram kiran Pachigolla Jun 14 '13 at 07:40
-
How about displaying the login page - so that mayb a different user can use the app without launching again or if thr first user accidentally clicked logout. – midhunhk Jun 14 '13 at 07:45
-
Your question doesn't explain much. Are you talking about login locally through database, or maintaining session or usingweb services or through 3rd party apis. Make it clear and in the meantime read [this](http://stackoverflow.com/questions/how-to-ask). – Mihir Jun 14 '13 at 07:49
-
http://stackoverflow.com/questions/8615431/close-all-running-activities-in-an-android-application/14870525#14870525] check this link – Sagar G. Jun 14 '13 at 07:58
-
@silverback that's good one. but on login screen when I press back It goes to another activity. If i disabled back button then app will run in background. isn't there a good way to exit app? – Mr.India Jun 14 '13 at 08:03
4 Answers
You could start the home activity after the user has logged out:
According to the Android documentation :
This is the home activity, that is the first activity that is displayed when the device boots.
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent );

- 710
- 1
- 8
- 16
You shouldn't exit the app, you should merely clear your session token and then send the user back to the homescreen (terminate the session in other words). Let the ActivityManager kill your app.

- 13,423
- 6
- 32
- 45
The Android operating system handles when an app "exits" - typically when the amount of free memory is getting low. When your user logs out, you should just return to the login screen in my opinion, and then let the user navigate away. The process may keep running in the background, or it may get destroyed to free system resources.
Check out the official tutorial on Activity lifecycle to get a better idea about what's going on in the OS regarding exiting apps, etc.

- 4,218
- 1
- 25
- 35
Its not a very feasible solution but will work for you.
Hope you are storing user's login information in SharedPreference
or in DB.once User hit logout button clear the login data and call finish()
on current activity,and in all activity's onResume()
check for whether user is logged in or not,If not call finish()
too.
Hope this is the solution you are looking for.

- 7,548
- 8
- 45
- 72