Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does moveTaskToBack() do?

Tags:

android

From the documentation:

public boolean moveTaskToBack (boolean nonRoot)

Move the task containing this activity to the back of the activity stack. The activity's order within the task is unchanged.

What exactly does "Move the task containing this activity to the back of the activity stack" mean? I know that each task is a stack of activities, but according the the above sentence, it seems there is also a global stack of tasks as well?

When I try this method out, the current activity moves to the background, and the behaviour seems very much like when clicking the Home button (e.g. the activity is not destroyed and can be resumed later). Is there any difference between calling this function and pressing the Home button?

like image 460
Chin Avatar asked Jun 12 '15 02:06

Chin


1 Answers

There is not a "global stack of tasks." There's a global stack of activities, which can be from one app or from multiple. Let's say you have an app where you can click a link, bringing you to your browser. If the browser then calls a moveTaskToBack() method, then the original app activity will open, with the previous activities on the backstack still in place.

Now imagine instead of calling the moveTaskToBack() method, the user presses the Home button. Now, pressing Back on your phone will not take you back to the original app. You'll just stay on the home screen.

like image 96
adao7000 Avatar answered Oct 22 '22 10:10

adao7000