About android launchmode "singleTask"

Viewed 43555

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

3 Answers

Correct, whenever singleTask activity is launched it comes foreground clearing all activities currently present above it, if your singleTask activity is on the top, it will behave same as singleTop.

P.S - onCreate is not called 2nd time, instead onNewIntent is called.

check this link, very well explained about launchmodes. https://medium.com/android-news/android-activity-launch-mode-e0df1aa72242

Related