to top
Android APIs
public class

TaskStackBuilder

extends Object
java.lang.Object
   ↳ android.app.TaskStackBuilder

Class Overview

Utility class for constructing synthetic back stacks for cross-task navigation on Android 3.0 and newer.

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI, accessible through the software-provided Recents key on the navigation or system bar. On devices with the older hardware button configuration the recents UI can be accessed with a long press on the Home key.

When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.

TaskStackBuilder provides a way to obey the correct conventions around cross-task navigation.

About Navigation

For more detailed information about tasks, the back stack, and navigation design guidelines, please read Tasks and Back Stack from the developer guide and Navigation from the design guide.

Summary

Public Methods
TaskStackBuilder addNextIntent(Intent nextIntent)
Add a new Intent to the task stack.
TaskStackBuilder addNextIntentWithParentStack(Intent nextIntent)
Add a new Intent with the resolved chain of parents for the target activity to the task stack.
TaskStackBuilder addParentStack(Activity sourceActivity)
Add the activity parent chain as specified by the getParentActivityIntent() method of the activity specified and the parentActivityName attributes of each successive activity (or activity-alias) element in the application's manifest to the task stack builder.
TaskStackBuilder addParentStack(ComponentName sourceActivityName)
Add the activity parent chain as specified by the parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.
TaskStackBuilder addParentStack(Class<?> sourceActivityClass)
Add the activity parent chain as specified by the parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.
static TaskStackBuilder create(Context context)
Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.
Intent editIntentAt(int index)
Return the intent at the specified index for modification.
int getIntentCount()
Intent[] getIntents()
Return an array containing the intents added to this builder.
PendingIntent getPendingIntent(int requestCode, int flags)
Obtain a PendingIntent for launching the task constructed by this builder so far.
PendingIntent getPendingIntent(int requestCode, int flags, Bundle options)
Obtain a PendingIntent for launching the task constructed by this builder so far.
void startActivities(Bundle options)
Start the task stack constructed by this builder.
void startActivities()
Start the task stack constructed by this builder.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public TaskStackBuilder addNextIntent (Intent nextIntent)

Added in API level 16

Add a new Intent to the task stack. The most recently added Intent will invoke the Activity at the top of the final task stack.

Parameters
nextIntent Intent for the next Activity in the synthesized task stack
Returns
  • This TaskStackBuilder for method chaining

public TaskStackBuilder addNextIntentWithParentStack (Intent nextIntent)

Added in API level 16

Add a new Intent with the resolved chain of parents for the target activity to the task stack.

This is equivalent to calling addParentStack with the resolved ComponentName of nextIntent (if it can be resolved), followed by addNextIntent with nextIntent.

Parameters
nextIntent Intent for the topmost Activity in the synthesized task stack. Its chain of parents as specified in the manifest will be added.
Returns
  • This TaskStackBuilder for method chaining.

public TaskStackBuilder addParentStack (Activity sourceActivity)

Added in API level 16

Add the activity parent chain as specified by the getParentActivityIntent() method of the activity specified and the parentActivityName attributes of each successive activity (or activity-alias) element in the application's manifest to the task stack builder.

Parameters
sourceActivity All parents of this activity will be added
Returns
  • This TaskStackBuilder for method chaining

public TaskStackBuilder addParentStack (ComponentName sourceActivityName)

Added in API level 16

Add the activity parent chain as specified by the parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.

Parameters
sourceActivityName Must specify an Activity component. All parents of this activity will be added
Returns
  • This TaskStackBuilder for method chaining

public TaskStackBuilder addParentStack (Class<?> sourceActivityClass)

Added in API level 16

Add the activity parent chain as specified by the parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.

Parameters
sourceActivityClass All parents of this activity will be added
Returns
  • This TaskStackBuilder for method chaining

public static TaskStackBuilder create (Context context)

Added in API level 16

Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.

Parameters
context The context that will launch the new task stack or generate a PendingIntent
Returns
  • A new TaskStackBuilder

public Intent editIntentAt (int index)

Added in API level 16

Return the intent at the specified index for modification. Useful if you need to modify the flags or extras of an intent that was previously added, for example with addParentStack(Activity).

Parameters
index Index from 0-getIntentCount()
Returns
  • the intent at position index

public int getIntentCount ()

Added in API level 16

Returns
  • the number of intents added so far.

public Intent[] getIntents ()

Added in API level 16

Return an array containing the intents added to this builder. The intent at the root of the task stack will appear as the first item in the array and the intent at the top of the stack will appear as the last item.

Returns
  • An array containing the intents added to this builder.

public PendingIntent getPendingIntent (int requestCode, int flags)

Added in API level 16

Obtain a PendingIntent for launching the task constructed by this builder so far.

Parameters
requestCode Private request code for the sender
flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags supported by fillIn(Intent, int) to control which unspecified parts of the intent that can be supplied when the actual send happens.
Returns
  • The obtained PendingIntent

public PendingIntent getPendingIntent (int requestCode, int flags, Bundle options)

Added in API level 16

Obtain a PendingIntent for launching the task constructed by this builder so far.

Parameters
requestCode Private request code for the sender
flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags supported by fillIn(Intent, int) to control which unspecified parts of the intent that can be supplied when the actual send happens.
options Additional options for how the Activity should be started. See Context.startActivity(Intent, Bundle) for more details.
Returns
  • The obtained PendingIntent

public void startActivities (Bundle options)

Added in API level 16

Start the task stack constructed by this builder.

Parameters
options Additional options for how the Activity should be started. See Context.startActivity(Intent, Bundle) for more details.

public void startActivities ()

Added in API level 16

Start the task stack constructed by this builder.