ActivityManager.AppTask
public
static
class
ActivityManager.AppTask
extends Object
| java.lang.Object | |
| ↳ | android.app.ActivityManager.AppTask |
The AppTask allows you to manage your own application's tasks.
See ActivityManager.getAppTasks()
Summary
Public methods | |
|---|---|
void
|
finishAndRemoveTask()
Finishes all activities in this task and removes it from the recent tasks list. |
ActivityManager.RecentTaskInfo
|
getTaskInfo()
Get the RecentTaskInfo associated with this task. |
void
|
moveTaskTo(TaskLocation location, Executor executor, OutcomeReceiver<TaskLocation, Exception> callback)
Repositions the task to the specified |
void
|
moveToFront()
Bring this task to the foreground. |
void
|
setExcludeFromRecents(boolean exclude)
Modify the |
void
|
startActivity(Context context, Intent intent, Bundle options)
Start an activity in this task. |
Inherited methods | |
|---|---|
Public methods
finishAndRemoveTask
public void finishAndRemoveTask ()
Finishes all activities in this task and removes it from the recent tasks list.
getTaskInfo
public ActivityManager.RecentTaskInfo getTaskInfo ()
Get the RecentTaskInfo associated with this task.
| Returns | |
|---|---|
ActivityManager.RecentTaskInfo |
The RecentTaskInfo for this task, or null if the task no longer exists. |
moveTaskTo
public void moveTaskTo (TaskLocation location, Executor executor, OutcomeReceiver<TaskLocation, Exception> callback)
Repositions the task to the specified TaskLocation.
If the TaskLocation's bounds are invalid (i.e. too small or not fully inside the
target display), the request will be rejected.
When the repositioning request is approved or rejected, the callback will be
invoked. If the request is approved, the callback will receive a TaskLocation
containing the new display ID and bounds of the task. The final display ID and bounds may
be adjusted to the closest acceptable states from the requested ones at the system's
discretion.
If the request is rejected, the callback will receive an exception with a descriptive
message accessible via Exception.getMessage(). This exception will be one of
the following:
SecurityExceptionif the requester doesn't hold the permission required to use this method;SecurityExceptionif this task cannot be placed as requested due to violation of the Background Activity Launch (BAL) policy;IllegalStateExceptionif the task is not in a state that allows it to change itsTaskLocationprogrammatically at runtime of the request;SecurityExceptionif this task cannot be placed on the target display requested. This can happen when the display is not trusted and not owned by the calling app;IllegalArgumentExceptionif theTaskLocationprovided does not include a valid display ID or the bounds provided are not fully contained inside the given display or the bounds provided are smaller than the minimum size defined in the CDD in either direction.
It is allowed to move a task to a display with which the call of
ERROR(ActivityManager.isTaskMoveAllowedOnDisplay()/android.app.ActivityManager#isTaskMoveAllowedOnDisplay() ActivityManager.isTaskMoveAllowedOnDisplay()) returns false, but the task
won't be allowed to be programmatically moved again until users take actions to make the
same task movable again.
If the task stays on its original display, its z-order will not be affected. Otherwise,
if the task moves to a different display, it will become focused.
Requires Manifest.permission.REPOSITION_SELF_WINDOWS
| Parameters | |
|---|---|
location |
TaskLocation: TaskLocation with the target display or Display.INVALID_DISPLAY if the target display is the current display,
and the new desired bounds.
This value cannot be null. |
executor |
Executor: an Executor used to invoke the callback.
This value cannot be null.
Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is
used. To dispatch events through the main thread of your
application, you can use
Context.getMainExecutor().
Otherwise, provide an Executor that dispatches to an appropriate thread. |
callback |
OutcomeReceiver: a callback to receive the result of the request.
This value cannot be null. |
moveToFront
public void moveToFront ()
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.
setExcludeFromRecents
public void setExcludeFromRecents (boolean exclude)
Modify the Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS flag in the root
Intent of this AppTask.
| Parameters | |
|---|---|
exclude |
boolean: If true, Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS will
be set; otherwise, it will be cleared. |
startActivity
public void startActivity (Context context, Intent intent, Bundle options)
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 | |
|---|---|
context |
Context |
intent |
Intent: The Intent describing the new activity to be launched on the task. |
options |
Bundle: Optional launch options. |