About android launchmode "singleTask"

cn1h picture cn1h · Jul 26, 2012 · Viewed 36.2k times · Source

I read the android developer guide and some articles in internet, I'm still confusing about the singleTask launchmode. Lets take an example:

User launch the App1, android starts a new task. Assume the App1 creates activities in follow order:

ActivityA -> ActivityB -> ActivityC

That's how task1 looks like.

Then user click the home buttom and choose to launch App2, so task1 goes in background and android start a new task: task2, user does something:

ActivityD -> ActivityE

now lets say ActivityE try to start ActivityB , and ActivityB has the launchmode singleTask.

What I understand is that task1 comes to frontend again and task2 goes to background. And task1 looks now like this:

ActivityA -> ActivityB

Which means:

  1. The ActivityC will be removed from task1 and ActivityB becomes to the top Activity.

  2. If user now click on "Back" button, he will come to ActivityA of task1 instead of back to ActivityE of task2

Am I right?

Thanks

Answer

Blundell picture Blundell · Jul 26, 2012

You sound right.

Why don't you test it.

There is also this app that can help explain launch mode:

https://play.google.com/store/apps/details?id=com.novoda.demos.activitylaunchmode

enter image description here

Sources are at https://github.com/gnorsilva/Activities-LaunchMode-demo