ZOFTINO.COM android and web dev tutorials

Android Tasks & Management

Task is a collection of activates, placed in a stack, which user interacted with by starting activities as user navigates an application. User starts an activity by pressing actionable area on a screen to view next screen. Android system keeps these sequence of screens or activities that user visited or started in a back stack as they are opened. These sequence of activities placed in a stack is called task.

Within an application flow, user can start an activity in a different application to use certain functionality of the app. Even this activity or screen is also part of the task of an app which started the activity in another application. That is the default behavior provided by android system.

Android system uses tasks to switch focus between apps and to provide back button functionality. When user is working with an app and tries to start a different app by going to home screen and clicking app icon, android system moves the current stack or task to background and starts a new task for the app user tried to open. A new task is created when you click an app icon on home screen if the app is not already opened. If application is already opened, it brings the existing task to foreground.

You can view all opened tasks on overview or recents screen which can be accessed by pressing overview button.

Android system uses task or stack to provide back button functionality as stack contains all previously visited screen in chronological order.

Management of Android tasks

Android system manages task and stack to provide above default behavior. But if you need to change the default behavior meaning you want to start separate task for some activities within you app, you can do so. But for most of the apps, system provided task and activity management gives best user experience.

You can define task behavior using different attributes of activity element in AndroidManifest.xml file. You can also customize tasking behavior by setting flags in the intents which start activities.

Intent flags let source activity to customize task behavior of target activity which it wants to start. Meaning activity which starts another activity can specify how the new activity should be associated with task source activity belongs to. Whereas attributes of activity element define how activity should be associated with tasks.

Intent task flags override activity element task attribute settings.

Activity element task attributes

Below are attributes of activity elements used to configure task, activity and stack behavior. Visit details page to know more about these activity attributes.

  • allowTaskReparenting
  • alwaysRetainTaskState
  • autoRemoveFromRecents
  • clearTaskOnLaunch
  • documentLaunchMode
  • excludeFromRecents
  • finishOnTaskLaunch
  • launchMode
  • maxRecents
  • noHistory
  • relinquishTaskIdentity
  • taskAffinity

Intent task flags

Below is the list of intent flags used to configure task, activity and stack behavior. Visit details page to know more about these intent flags.



Start activity in a new task with activity attribute setting.

<activity android:name=".CashbackActivity" android:documentLaunchMode="always"></activity> 

LaunchMode singleTask activity, it can only be root of a task.

    <activity android:name=".CashbackActivity" android:launchMode="singleTask">

Create a new task with intent

Intent nIntent = new Intent(this, ViewCouponActivity.class);

Activity will be removed from stack when user is away from the activity.

Intent nIntent = new Intent(this, ViewCouponActivity.class);