Pankaj Kumar
Pankaj Kumar

Reputation: 82948

Task and Activity stack : what is difference between both.

I followed some tutorials but got confused with "Activity stack" and "Task".

Is this is only difference that Activity stack made up of one or more task(S)?

Give some example please.

Upvotes: 31

Views: 12564

Answers (2)

Scott
Scott

Reputation: 99

A task is not an application. The former is a set of Activities that the user has visited, while the latter is a collection of Android components (Activities, Services, ContentProviders and BroadcastReceivers) that are declared in an application's manifest.

The Activities of a given task can come from other applications as well as the current application. Taken together, these Activities represent the "path" that a user has taken to accomplish some objective. They are stored in the task's back stack in LIFO order; each task has its own back stack.

Task management, either through attributes such as launchMode, taskAffinity, etc, and/or intent flags, allows us to control the relationship between tasks and Activities.

For more information, please see: https://developer.android.com/guide/components/activities/tasks-and-back-stack

Upvotes: 2

pedr0
pedr0

Reputation: 3011

Activities and Tasks

As noted earlier, one Activity can start another, including one defined in a different Application. Suppose, for example, that you'd like to let users display a street map of some location. There's already an activity that can do that, so all your activity needs to do is put together an Intent object with the required information and pass it to startActivity(). The map viewer will display the map. When the user hits the BACK key, your activity will reappear on screen.

To the user, it will seem as if the map viewer is part of the same application as your activity, even though it's defined in another application and runs in that application's process. Android maintains this user experience by keeping both activities in the same task. Simply put, a task is what the user experiences as an "application". It's a group of related activities, arranged in a stack.

Task = Application = Set of activities.

Upvotes: 48

Related Questions