Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clearTaskOnLaunch HowTo?

Reading the Android documentation and some of the answers here have left it ambiguous how clearTaskOnLaunch is supposed to work. Specifically

1) How is the root activity identified? Is it simply the one with the DEFAULT, LAUNCHER or MAIN intent filters?

2) Launching from "home screen" in the documentation means the OS home screen or applications list, correct? I.e. from not within an application.

3) Does clearTaskOnLaunch clear the activity stack whenever that activity is launched from the home screen, or just when that activity's process is started from the home screen? Because the docs indicate the former, but posts here indicate the latter. I guess this depends on what the definition of "launch" is.

EDIT: 4) Does "clearing" the activity stack mean literally erasing it, or having the activities cycle through onCreate() and finish()?

I've manipulated clearTaskOnLaunch in every way imaginable with absolutely no effect. I've placed it in my root activity in the manifest, then placed it in EVERY activity just to be sure, restarted my application after killing the process entirely, etc. My activity stack is simply not being cleared.

Can anyone offer a complete overview on how to implement clearTaskOnLaunch?

like image 386
Nathan Fig Avatar asked Mar 28 '11 15:03

Nathan Fig


1 Answers

Here's a complete response from an Android engineer on Groups: http://groups.google.com/group/android-developers/browse_thread/thread/da024bcaf4e1960f

Reading the Android documentation and some of the answers here (and on StackOverflow) have left it ambiguous how clearTaskOnLaunch is supposed to behave, specifically:

1) Does "clearing" the activity stack mean literally erasing it, or having the activities cycle through onCreate() and finish()?

All activities in the stack being cleared will go through the lifecycle as if they called finish(). The root activity will generally be kept as-is.

2) How is the root activity identified? Is it simply the one with the DEFAULT, LAUNCHER or MAIN intent filters?

This is basically the first activity in the stack. The Intent is the Intent used to start the stack.

3) Launching from "home screen" in the documentation means the OS home screen or applications list, correct? I.e. from not within an application.

It doesn't really matter -- it is just whoever sets Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED. The standard launcher sets this when launching an app from an icon. You can set it yourself if you want.

4) Does clearTaskOnLaunch clear the activity stack whenever that activity is launched from the home screen, or just when that activity's process is started from the home screen? Because the docs indicate the former, but posts here indicate the latter. I guess this depends on what the definition of "launch" is?

Whenever it is launched from the home screen. The fact that processes are killed and restarted should be invisible to the user.

I've manipulated clearTaskOnLaunch in every way imaginable with absolutely no effect. I've placed it in my root activity in the manifest, then placed it in EVERY activity just to be sure, restarted my application after killing the process entirely, etc. My activity stack is simply not being cleared.

Settings uses this as an example -- if you go in to settings, dig down a bit, press home, and then launch settings again, you will end up in the home activity instead of wherever you last went to. It just sets the flag on the main activity of its app.

like image 148
Nathan Fig Avatar answered Sep 21 '22 09:09

Nathan Fig