Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task and Activity stack : what is difference between both.

Tags:

android

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

  • Because both starts when a new activity is created.
  • Activity stack keeps a navigation history of activities, and Task is a sequence of activities.

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

Give some example please.

like image 622
Pankaj Kumar Avatar asked Jan 13 '11 07:01

Pankaj Kumar


People also ask

What is an activity stack?

A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.

What is Flag activity new task?

launchMode — singleTask | flag — FLAG_ACTIVITY_NEW_TASK: If an Activity do not exist in an already created Task, then it starts the Activity in a new Task with Activity's new instance at the root of the Task's back stack, else the Task is brought forward with the Activity's last state restored and this Activity ...

How do I get activity stack?

This example demonstrate about How to get top activity name in activity stack. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is the difference between activity and layout?

Layout is where you organize the views in your page. But without activity, they have no meaning. Because in activity, you have to get these views and use them programmaticaly. All together, you load views from layout to activity and in activies you implement your whole program.


2 Answers

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.

like image 151
pedr0 Avatar answered Oct 20 '22 09:10

pedr0


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

like image 23
Scott Avatar answered Oct 20 '22 09:10

Scott