clearTaskOnLaunch HowTo?

后端 未结 1 2056
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 06:42

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

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 07:11

    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.

    0 讨论(0)
提交回复
热议问题