Added in API level 16

TaskStackBuilder


open class TaskStackBuilder
kotlin.Any
   ↳ android.app.TaskStackBuilder

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.

Summary

Public methods
open TaskStackBuilder!
addNextIntent(nextIntent: Intent!)

Add a new Intent to the task stack.

open TaskStackBuilder!

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

open TaskStackBuilder!
addParentStack(sourceActivity: Activity!)

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.

open TaskStackBuilder!
addParentStack(sourceActivityName: ComponentName!)

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.

open TaskStackBuilder!
addParentStack(sourceActivityClass: Class<*>!)

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.

open static TaskStackBuilder!
create(context: Context!)

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

open Intent!
editIntentAt(index: Int)

Return the intent at the specified index for modification.

open Int

open Array<Intent!>

Return an array containing the intents added to this builder.

open PendingIntent!
getPendingIntent(requestCode: Int, flags: Int)

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

open PendingIntent!
getPendingIntent(requestCode: Int, flags: Int, options: Bundle!)

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

open Unit

Start the task stack constructed by this builder.

open Unit

Start the task stack constructed by this builder.

Public methods

addNextIntent

Added in API level 16
open fun addNextIntent(nextIntent: Intent!): TaskStackBuilder!

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!: Intent for the next Activity in the synthesized task stack
Return
TaskStackBuilder! This TaskStackBuilder for method chaining

addNextIntentWithParentStack

Added in API level 16
open fun addNextIntentWithParentStack(nextIntent: Intent!): TaskStackBuilder!

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!: Intent for the topmost Activity in the synthesized task stack. Its chain of parents as specified in the manifest will be added.
Return
TaskStackBuilder! This TaskStackBuilder for method chaining.

addParentStack

Added in API level 16
open fun addParentStack(sourceActivity: Activity!): TaskStackBuilder!

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 Activity!: All parents of this activity will be added
Return
TaskStackBuilder! This TaskStackBuilder for method chaining

addParentStack

Added in API level 16
open fun addParentStack(sourceActivityName: ComponentName!): TaskStackBuilder!

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 ComponentName!: Must specify an Activity component. All parents of this activity will be added
Return
TaskStackBuilder! This TaskStackBuilder for method chaining

addParentStack

Added in API level 16
open fun addParentStack(sourceActivityClass: Class<*>!): TaskStackBuilder!

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 Class<*>!: All parents of this activity will be added
Return
TaskStackBuilder! This TaskStackBuilder for method chaining

create

Added in API level 16
open static fun create(context: Context!): TaskStackBuilder!

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

Parameters
context Context!: The context that will launch the new task stack or generate a PendingIntent
Return
TaskStackBuilder! A new TaskStackBuilder

editIntentAt

Added in API level 16
open fun editIntentAt(index: Int): Intent!

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(android.app.Activity).

Parameters
index Int: Index from 0-getIntentCount()
Return
Intent! the intent at position index

getIntentCount

Added in API level 16
open fun getIntentCount(): Int
Return
Int the number of intents added so far.

getIntents

Added in API level 16
open fun getIntents(): Array<Intent!>

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.

Return
Array<Intent!> An array containing the intents added to this builder. This value cannot be null.

getPendingIntent

Added in API level 16
open fun getPendingIntent(
    requestCode: Int,
    flags: Int,
    options: Bundle!
): PendingIntent!

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

Parameters
requestCode Int: Private request code for the sender
flags Int: May be PendingIntent.FLAG_ONE_SHOT, PendingIntent.FLAG_NO_CREATE, PendingIntent.FLAG_CANCEL_CURRENT, PendingIntent.FLAG_UPDATE_CURRENT, or any of the flags supported by Intent.fillIn(Intent, int) 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 android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
options Bundle!: Additional options for how the Activity should be started. See android.content.Context#startActivity(Intent, Bundle) Context.startActivity(Intent, Bundle)} for more details.
Return
PendingIntent! The obtained PendingIntent

startActivities

Added in API level 16
open fun startActivities(): Unit

Start the task stack constructed by this builder.

startActivities

Added in API level 16
open fun startActivities(options: Bundle!): Unit

Start the task stack constructed by this builder.

Parameters
options Bundle!: Additional options for how the Activity should be started. See android.content.Context#startActivity(Intent, Bundle) Context.startActivity(Intent, Bundle)} for more details.