TaskStackBuilder
class TaskStackBuilder : MutableIterable<Intent!>
kotlin.Any | |
↳ | androidx.core.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 backward-compatible way to obey the correct conventions around cross-task navigation on the device's version of the platform. On devices running Android 3.0 or newer, calls to the startActivities()
method or sending the PendingIntent
generated by getPendingIntent(int, int)
will construct the synthetic back stack as prescribed. On devices running older versions of the platform, these same calls will invoke the topmost activity in the supplied stack, ignoring the rest of the synthetic stack and allowing the back key to navigate back to the previous task.
Summary
Nested classes | |
---|---|
abstract |
Public methods | |
---|---|
TaskStackBuilder |
addNextIntent(@NonNull nextIntent: Intent) Add a new Intent to the task stack. |
TaskStackBuilder |
addNextIntentWithParentStack(@NonNull nextIntent: Intent) Add a new Intent with the resolved chain of parents for the target activity to the task stack. |
TaskStackBuilder |
addParentStack(@NonNull sourceActivity: Activity) Add the activity parent chain as specified by manifest <meta-data> elements to the task stack builder. |
TaskStackBuilder |
addParentStack(@NonNull sourceActivityClass: Class<*>) Add the activity parent chain as specified by manifest <meta-data> elements to the task stack builder. |
TaskStackBuilder! |
addParentStack(sourceActivityName: ComponentName!) Add the activity parent chain as specified by manifest <meta-data> elements to the task stack builder. |
static TaskStackBuilder |
Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities. |
Intent? |
editIntentAt(index: Int) Return the intent at the specified index for modification. |
static TaskStackBuilder! |
Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities. |
Intent! |
Get the intent at the specified index. |
Int | |
Array<Intent!> |
Return an array containing the intents added to this builder. |
PendingIntent? |
getPendingIntent(requestCode: Int, flags: Int) Obtain a |
PendingIntent? |
getPendingIntent(requestCode: Int, flags: Int, @Nullable options: Bundle?) Obtain a |
MutableIterator<Intent!> |
iterator() |
Unit |
Start the task stack constructed by this builder. |
Unit |
startActivities(@Nullable options: Bundle?) Start the task stack constructed by this builder. |
Public methods
addNextIntent
@NonNull fun addNextIntent(@NonNull 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
@NonNull fun addNextIntentWithParentStack(@NonNull 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
@NonNull fun addParentStack(@NonNull sourceActivity: Activity): TaskStackBuilder
Add the activity parent chain as specified by manifest <meta-data> elements to the task stack builder.
Parameters | |
---|---|
sourceActivity |
Activity: All parents of this activity will be added |
Return | |
---|---|
TaskStackBuilder |
This TaskStackBuilder for method chaining |
addParentStack
@NonNull fun addParentStack(@NonNull sourceActivityClass