Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/app/TaskStackBuilder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/app/TaskStackBuilder#inhmethods)

# TaskStackBuilder

*** ** * ** ***


`
public


class
TaskStackBuilder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.TaskStackBuilder |

<br />

*** ** * ** ***

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](https://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack) from the developer guide and [Navigation](https://developer.android.com/design/patterns/navigation) from the design guide.

<br />

## Summary

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/TaskStackBuilder` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#addNextIntent(android.content.Intent)(https://developer.android.com/reference/android/content/Intent nextIntent) ` Add a new Intent to the task stack. |
| ` https://developer.android.com/reference/android/app/TaskStackBuilder` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#addNextIntentWithParentStack(android.content.Intent)(https://developer.android.com/reference/android/content/Intent nextIntent) ` Add a new Intent with the resolved chain of parents for the target activity to the task stack. |
| ` https://developer.android.com/reference/android/app/TaskStackBuilder` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#addParentStack(android.content.ComponentName)(https://developer.android.com/reference/android/content/ComponentName sourceActivityName) ` Add the activity parent chain as specified by the `https://developer.android.com/reference/android/R.attr#parentActivityName` attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder. |
| ` https://developer.android.com/reference/android/app/TaskStackBuilder` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#addParentStack(android.app.Activity)(https://developer.android.com/reference/android/app/Activity sourceActivity) ` Add the activity parent chain as specified by the `https://developer.android.com/reference/android/app/Activity#getParentActivityIntent()` method of the activity specified and the `https://developer.android.com/reference/android/R.attr#parentActivityName` attributes of each successive activity (or activity-alias) element in the application's manifest to the task stack builder. |
| ` https://developer.android.com/reference/android/app/TaskStackBuilder` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#addParentStack(java.lang.Class<?>)(https://developer.android.com/reference/java/lang/Class<?> sourceActivityClass) ` Add the activity parent chain as specified by the `https://developer.android.com/reference/android/R.attr#parentActivityName` attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder. |
| ` static https://developer.android.com/reference/android/app/TaskStackBuilder` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#create(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities. |
| ` https://developer.android.com/reference/android/content/Intent` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#editIntentAt(int)(int index) ` Return the intent at the specified index for modification. |
| ` int` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#getIntentCount()() ` |
| ` https://developer.android.com/reference/android/content/Intent` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#getIntents()() ` Return an array containing the intents added to this builder. |
| ` https://developer.android.com/reference/android/app/PendingIntent` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#getPendingIntent(int,%20int)(int requestCode, int flags) ` Obtain a `https://developer.android.com/reference/android/app/PendingIntent` for launching the task constructed by this builder so far. |
| ` https://developer.android.com/reference/android/app/PendingIntent` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#getPendingIntent(int,%20int,%20android.os.Bundle)(int requestCode, int flags, https://developer.android.com/reference/android/os/Bundle options) ` Obtain a `https://developer.android.com/reference/android/app/PendingIntent` for launching the task constructed by this builder so far. |
| ` void` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#startActivities()() ` Start the task stack constructed by this builder. |
| ` void` | ` https://developer.android.com/reference/android/app/TaskStackBuilder#startActivities(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle options) ` Start the task stack constructed by this builder. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public methods

### addNextIntent

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TaskStackBuilder addNextIntent (Intent nextIntent)
```

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.

<br />

| Parameters ||
|---|---|
| `nextIntent` | `Intent`: Intent for the next Activity in the synthesized task stack <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/TaskStackBuilder` | This TaskStackBuilder for method chaining <br /> |

### addNextIntentWithParentStack

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TaskStackBuilder addNextIntentWithParentStack (Intent nextIntent)
```

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

This is equivalent to calling `https://developer.android.com/reference/android/app/TaskStackBuilder#addParentStack(android.content.ComponentName)`
with the resolved ComponentName of nextIntent (if it can be resolved), followed by
`https://developer.android.com/reference/android/app/TaskStackBuilder#addNextIntent(android.content.Intent)` with nextIntent.

<br />

<br />

| Parameters ||
|---|---|
| `nextIntent` | `Intent`: Intent for the topmost Activity in the synthesized task stack. Its chain of parents as specified in the manifest will be added. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/TaskStackBuilder` | This TaskStackBuilder for method chaining. <br /> |

### addParentStack

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TaskStackBuilder addParentStack (ComponentName sourceActivityName)
```

Add the activity parent chain as specified by the
`https://developer.android.com/reference/android/R.attr#parentActivityName` attribute of the activity
(or activity-alias) element in the application's manifest to the task stack builder.

<br />

| Parameters ||
|---|---|
| `sourceActivityName` | `ComponentName`: Must specify an Activity component. All parents of this activity will be added <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/TaskStackBuilder` | This TaskStackBuilder for method chaining <br /> |

### addParentStack

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TaskStackBuilder addParentStack (Activity sourceActivity)
```

Add the activity parent chain as specified by the
`https://developer.android.com/reference/android/app/Activity#getParentActivityIntent()` method of the activity
specified and the `https://developer.android.com/reference/android/R.attr#parentActivityName` attributes
of each successive activity (or activity-alias) element in the application's manifest
to the task stack builder.

<br />

| Parameters ||
|---|---|
| `sourceActivity` | `Activity`: All parents of this activity will be added <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/TaskStackBuilder` | This TaskStackBuilder for method chaining <br /> |

### addParentStack

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public TaskStackBuilder addParentStack (Class<?> sourceActivityClass)
```

Add the activity parent chain as specified by the
`https://developer.android.com/reference/android/R.attr#parentActivityName` attribute of the activity
(or activity-alias) element in the application's manifest to the task stack builder.

<br />

| Parameters ||
|---|---|
| `sourceActivityClass` | `Class`: All parents of this activity will be added <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/TaskStackBuilder` | This TaskStackBuilder for method chaining <br /> |

### create

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static TaskStackBuilder create (Context context)
```

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

<br />

| Parameters ||
|---|---|
| `context` | `Context`: The context that will launch the new task stack or generate a PendingIntent <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/TaskStackBuilder` | A new TaskStackBuilder <br /> |

### editIntentAt

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Intent editIntentAt (int index)
```

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 `https://developer.android.com/reference/android/app/TaskStackBuilder#addParentStack(android.app.Activity)`.

<br />

| Parameters ||
|---|---|
| `index` | `int`: Index from 0-getIntentCount() <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Intent` | the intent at position index <br /> |

### getIntentCount

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getIntentCount ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the number of intents added so far. <br /> |

### getIntents

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Intent[] getIntents ()
```

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.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Intent` | An array containing the intents added to this builder. This value cannot be `null`. <br /> |

### getPendingIntent

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public PendingIntent getPendingIntent (int requestCode, 
                int flags)
```

Obtain a `https://developer.android.com/reference/android/app/PendingIntent` for launching the task constructed by this builder so far.

<br />

| Parameters ||
|---|---|
| `requestCode` | `int`: Private request code for the sender <br /> |
| `flags` | `int`: May be `https://developer.android.com/reference/android/app/PendingIntent#FLAG_ONE_SHOT`, `https://developer.android.com/reference/android/app/PendingIntent#FLAG_NO_CREATE`, `https://developer.android.com/reference/android/app/PendingIntent#FLAG_CANCEL_CURRENT`, `https://developer.android.com/reference/android/app/PendingIntent#FLAG_UPDATE_CURRENT`, or any of the flags supported by `https://developer.android.com/reference/android/content/Intent#fillIn(android.content.Intent,%20int)` to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_ONE_SHOT` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_NO_CREATE` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_CANCEL_CURRENT` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_UPDATE_CURRENT` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_MUTABLE` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_ACTION` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_DATA` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_CATEGORIES` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_COMPONENT` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_PACKAGE` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_SOURCE_BOUNDS` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_SELECTOR` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_CLIP_DATA` |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent` | The obtained PendingIntent <br /> |

### getPendingIntent

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Obtain a `https://developer.android.com/reference/android/app/PendingIntent` for launching the task constructed by this builder so far.

<br />

| Parameters ||
|---|---|
| `requestCode` | `int`: Private request code for the sender <br /> |
| `flags` | `int`: May be `https://developer.android.com/reference/android/app/PendingIntent#FLAG_ONE_SHOT`, `https://developer.android.com/reference/android/app/PendingIntent#FLAG_NO_CREATE`, `https://developer.android.com/reference/android/app/PendingIntent#FLAG_CANCEL_CURRENT`, `https://developer.android.com/reference/android/app/PendingIntent#FLAG_UPDATE_CURRENT`, or any of the flags supported by `https://developer.android.com/reference/android/content/Intent#fillIn(android.content.Intent,%20int)` to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_ONE_SHOT` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_NO_CREATE` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_CANCEL_CURRENT` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_UPDATE_CURRENT` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_MUTABLE` - `https://developer.android.com/reference/android/app/PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_ACTION` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_DATA` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_CATEGORIES` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_COMPONENT` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_PACKAGE` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_SOURCE_BOUNDS` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_SELECTOR` - `https://developer.android.com/reference/android/content/Intent#FILL_IN_CLIP_DATA` |
| `options` | `Bundle`: Additional options for how the Activity should be started. See `https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent,%20android.os.Bundle)` Context.startActivity(Intent, Bundle)} for more details. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent` | The obtained PendingIntent <br /> |

### startActivities

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startActivities ()
```

Start the task stack constructed by this builder.

<br />

### startActivities

Added in [API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startActivities (Bundle options)
```

Start the task stack constructed by this builder.

<br />

| Parameters ||
|---|---|
| `options` | `Bundle`: Additional options for how the Activity should be started. See `https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent,%20android.os.Bundle)` Context.startActivity(Intent, Bundle)} for more details. <br /> |