Stay organized with collections
Save and categorize content based on your preferences.
AppTask
open class AppTask
The AppTask allows you to manage your own application's tasks. See android.app.ActivityManager#getAppTasks()
Summary
Public methods
finishAndRemoveTask
open fun finishAndRemoveTask(): Unit
Finishes all activities in this task and removes it from the recent tasks list.
moveToFront
open fun moveToFront(): Unit
Bring this task to the foreground. If it contains activities, they will be brought to the foreground with it and their instances re-created if needed. If it doesn't contain activities, the root activity of the task will be re-launched.
startActivity
open fun startActivity(
context: Context!,
intent: Intent!,
options: Bundle!
): Unit
Start an activity in this task. Brings the task to the foreground. If this task is not currently active (that is, its id < 0), then a new activity for the given Intent will be launched as the root of the task and the task brought to the foreground. Otherwise, if this task is currently active and the Intent does not specify an activity to launch in a new task, then a new activity for the given Intent will be launched on top of the task and the task brought to the foreground. If this task is currently active and the Intent specifies Intent.FLAG_ACTIVITY_NEW_TASK
or would otherwise be launched in to a new task, then the activity not launched but this task be brought to the foreground and a new intent delivered to the top activity if appropriate.
In other words, you generally want to use an Intent here that does not specify Intent.FLAG_ACTIVITY_NEW_TASK
or Intent.FLAG_ACTIVITY_NEW_DOCUMENT
, and let the system do the right thing.
Parameters |
intent |
Intent!: The Intent describing the new activity to be launched on the task. |
options |
Bundle!: Optional launch options. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ActivityManager.AppTask\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nAppTask\n=======\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/app/ActivityManager.AppTask \"View this page in Java\") \n\n```\nopen class AppTask\n```\n\n|---|------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.app.ActivityManager.AppTask](#) |\n\nThe AppTask allows you to manage your own application's tasks. See [android.app.ActivityManager#getAppTasks()](/reference/kotlin/android/app/ActivityManager#getAppTasks())\n\nSummary\n-------\n\n| Public methods ||\n|------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [finishAndRemoveTask](#finishAndRemoveTask())`()` Finishes all activities in this task and removes it from the recent tasks list. |\n| open [ActivityManager.RecentTaskInfo](/reference/kotlin/android/app/ActivityManager.RecentTaskInfo)! | [getTaskInfo](#getTaskInfo())`()` Get the RecentTaskInfo associated with this task. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [moveToFront](#moveToFront())`()` Bring this task to the foreground. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [setExcludeFromRecents](#setExcludeFromRecents(kotlin.Boolean))`(`exclude:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Modify the [Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS](../content/Intent.html#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:kotlin.Int) flag in the root Intent of this AppTask. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [startActivity](#startActivity(android.content.Context,%20android.content.Intent,%20android.os.Bundle))`(`context:` `[Context](../content/Context.html#)!`, `intent:` `[Intent](../content/Intent.html#)!`, `options:` `[Bundle](../os/Bundle.html#)!`)` Start an activity in this task. |\n\nPublic methods\n--------------\n\n### finishAndRemoveTask\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun finishAndRemoveTask(): Unit\n```\n\nFinishes all activities in this task and removes it from the recent tasks list. \n\n### getTaskInfo\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getTaskInfo(): ActivityManager.RecentTaskInfo!\n```\n\nGet the RecentTaskInfo associated with this task.\n\n| Return ||\n|-------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|\n| [ActivityManager.RecentTaskInfo](/reference/kotlin/android/app/ActivityManager.RecentTaskInfo)! | The RecentTaskInfo for this task, or null if the task no longer exists. |\n\n### moveToFront\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun moveToFront(): Unit\n```\n\nBring this task to the foreground. If it contains activities, they will be brought to the foreground with it and their instances re-created if needed. If it doesn't contain activities, the root activity of the task will be re-launched. \n\n### setExcludeFromRecents\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun setExcludeFromRecents(exclude: Boolean): Unit\n```\n\nModify the [Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS](../content/Intent.html#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:kotlin.Int) flag in the root Intent of this AppTask.\n\n| Parameters ||\n|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `exclude` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): If true, [Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS](../content/Intent.html#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:kotlin.Int) will be set; otherwise, it will be cleared. |\n\n### startActivity\n\nAdded in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun startActivity(\n context: Context!, \n intent: Intent!, \n options: Bundle!\n): Unit\n```\n\nStart an activity in this task. Brings the task to the foreground. If this task is not currently active (that is, its id \\\u003c 0), then a new activity for the given Intent will be launched as the root of the task and the task brought to the foreground. Otherwise, if this task is currently active and the Intent does not specify an activity to launch in a new task, then a new activity for the given Intent will be launched on top of the task and the task brought to the foreground. If this task is currently active and the Intent specifies [Intent.FLAG_ACTIVITY_NEW_TASK](../content/Intent.html#FLAG_ACTIVITY_NEW_TASK:kotlin.Int) or would otherwise be launched in to a new task, then the activity not launched but this task be brought to the foreground and a new intent delivered to the top activity if appropriate.\n\nIn other words, you generally want to use an Intent here that does not specify [Intent.FLAG_ACTIVITY_NEW_TASK](../content/Intent.html#FLAG_ACTIVITY_NEW_TASK:kotlin.Int) or [Intent.FLAG_ACTIVITY_NEW_DOCUMENT](../content/Intent.html#FLAG_ACTIVITY_NEW_DOCUMENT:kotlin.Int), and let the system do the right thing.\n\n| Parameters ||\n|-----------|--------------------------------------------------------------------------------------------------------|\n| `intent` | [Intent](../content/Intent.html#)!: The Intent describing the new activity to be launched on the task. |\n| `options` | [Bundle](../os/Bundle.html#)!: Optional launch options. |\n\n**See Also**"]]