public
class
ActivityManager
extends Object
java.lang.Object | |
↳ | android.app.ActivityManager |
Interact with the overall activities running in the system.
Nested classes | |
---|---|
class |
ActivityManager.AppTask
The AppTask allows you to manage your own application's tasks. |
class |
ActivityManager.MemoryInfo
Information you can retrieve about the available memory through
|
class |
ActivityManager.ProcessErrorStateInfo
Information you can retrieve about any processes that are in an error condition. |
class |
ActivityManager.RecentTaskInfo
Information you can retrieve about tasks that the user has most recently started or visited. |
class |
ActivityManager.RunningAppProcessInfo
Information you can retrieve about a running process. |
class |
ActivityManager.RunningServiceInfo
Information you can retrieve about a particular Service that is currently running in the system. |
class |
ActivityManager.RunningTaskInfo
Information you can retrieve about a particular task that is currently "running" in the system. |
class |
ActivityManager.TaskDescription
Information you can set and retrieve about the current activity within the recent task list. |
Constants | |
---|---|
String |
ACTION_REPORT_HEAP_LIMIT
Action an app can implement to handle reports from |
int |
LOCK_TASK_MODE_LOCKED
Full lock task mode is active. |
int |
LOCK_TASK_MODE_NONE
Lock task mode is not active. |
int |
LOCK_TASK_MODE_PINNED
App pinning mode is active. |
String |
META_HOME_ALTERNATE
|
int |
MOVE_TASK_NO_USER_ACTION
Flag for |
int |
MOVE_TASK_WITH_HOME
Flag for |
int |
RECENT_IGNORE_UNAVAILABLE
Provides a list that does not contain any recent tasks that currently are not available to the user. |
int |
RECENT_WITH_EXCLUDED
Flag for use with |
Public methods | |
---|---|
int
|
addAppTask(Activity activity, Intent intent, ActivityManager.TaskDescription description, Bitmap thumbnail)
Add a new |
boolean
|
clearApplicationUserData()
Permits an application to erase its own data from disk. |
void
|
clearWatchHeapLimit()
Clear a heap watch limit previously set by |
void
|
dumpPackageState(FileDescriptor fd, String packageName)
Perform a system dump of various state associated with the given application package name. |
Size
|
getAppTaskThumbnailSize()
Return the current design dimensions for |
List<ActivityManager.AppTask>
|
getAppTasks()
Get the list of tasks associated with the calling application. |
ConfigurationInfo
|
getDeviceConfigurationInfo()
Get the device configuration attributes. |
int
|
getLargeMemoryClass()
Return the approximate per-application memory class of the current device when an application is running with a large heap. |
int
|
getLauncherLargeIconDensity()
Get the preferred density of icons for the launcher. |
int
|
getLauncherLargeIconSize()
Get the preferred launcher icon size. |
int
|
getLockTaskModeState()
Return the current state of task locking. |
int
|
getMemoryClass()
Return the approximate per-application memory class of the current device. |
void
|
getMemoryInfo(ActivityManager.MemoryInfo outInfo)
Return general information about the memory state of the system. |
static
void
|
getMyMemoryState(ActivityManager.RunningAppProcessInfo outState)
Return global memory state information for the calling process. |
MemoryInfo[]
|
getProcessMemoryInfo(int[] pids)
Return information about the memory usage of one or more processes. |
List<ActivityManager.ProcessErrorStateInfo>
|
getProcessesInErrorState()
Returns a list of any processes that are currently in an error condition. |
List<ActivityManager.RecentTaskInfo>
|
getRecentTasks(int maxNum, int flags)
This method was deprecated
in API level 21.
As of |
List<ActivityManager.RunningAppProcessInfo>
|
getRunningAppProcesses()
Returns a list of application processes that are running on the device. |
PendingIntent
|
getRunningServiceControlPanel(ComponentName service)
Returns a PendingIntent you can start to show a control panel for the given running service. |
List<ActivityManager.RunningServiceInfo>
|
getRunningServices(int maxNum)
Return a list of the services that are currently running. |
List<ActivityManager.RunningTaskInfo>
|
getRunningTasks(int maxNum)
This method was deprecated
in API level 21.
As of |
boolean
|
isInLockTaskMode()
This method was deprecated
in API level 23.
Use |
boolean
|
isLowRamDevice()
Returns true if this is a low-RAM device. |
static
boolean
|
isRunningInTestHarness()
Returns "true" if device is running in a test harness. |
static
boolean
|
isUserAMonkey()
Returns "true" if the user interface is currently being messed with by a monkey. |
void
|
killBackgroundProcesses(String packageName)
Have the system immediately kill all background processes associated with the given package. |
void
|
moveTaskToFront(int taskId, int flags, Bundle options)
Ask that the task associated with a given task ID be moved to the front of the stack, so it is now visible to the user. |
void
|
moveTaskToFront(int taskId, int flags)
Equivalent to calling |
void
|
restartPackage(String packageName)
This method was deprecated
in API level 8.
This is now just a wrapper for
|
void
|
setWatchHeapLimit(long pssSize)
Request that the system start watching for the calling process to exceed a pss size as given here. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
String ACTION_REPORT_HEAP_LIMIT
Action an app can implement to handle reports from setWatchHeapLimit(long)
.
If your package has an activity handling this action, it will be launched with the
heap data provided to it the same way as ACTION_SEND
. Note that to
match the activty must support this action and a MIME type of "*/*".
Constant Value: "android.app.action.REPORT_HEAP_LIMIT"
int LOCK_TASK_MODE_LOCKED
Full lock task mode is active.
Constant Value: 1 (0x00000001)
int LOCK_TASK_MODE_NONE
Lock task mode is not active.
Constant Value: 0 (0x00000000)
int LOCK_TASK_MODE_PINNED
App pinning mode is active.
Constant Value: 2 (0x00000002)
String META_HOME_ALTERNATE
<meta-data>
name for a 'home' Activity that declares a package that is to be
uninstalled in lieu of the declaring one. The package named here must be
signed with the same certificate as the one declaring the <meta-data>
.
Constant Value: "android.app.home.alternate"
int MOVE_TASK_NO_USER_ACTION
Flag for moveTaskToFront(int, int)
: don't count this as a
user-instigated action, so the current activity will not receive a
hint that the user is leaving.
Constant Value: 2 (0x00000002)
int MOVE_TASK_WITH_HOME
Flag for moveTaskToFront(int, int)
: also move the "home"
activity along with the task, so it is positioned immediately behind
the task.
Constant Value: 1 (0x00000001)
int RECENT_IGNORE_UNAVAILABLE
Provides a list that does not contain any recent tasks that currently are not available to the user.
Constant Value: 2 (0x00000002)
int RECENT_WITH_EXCLUDED
Flag for use with getRecentTasks(int, int)
: return all tasks, even those
that have set their
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
flag.
Constant Value: 1 (0x00000001)
int addAppTask (Activity activity, Intent intent, ActivityManager.TaskDescription description, Bitmap thumbnail)
Add a new ActivityManager.AppTask
for the calling application. This will create a new
recents entry that is added to the end of all existing recents.
Parameters | |
---|---|
activity |
Activity :
The activity that is adding the entry. This is used to help determine
the context that the new recents entry will be in. |
intent |
Intent :
The Intent that describes the recents entry. This is the same Intent that
you would have used to launch the activity for it. In generally you will want to set
both FLAG_ACTIVITY_NEW_DOCUMENT and
FLAG_ACTIVITY_RETAIN_IN_RECENTS ; the latter is required since this recents
entry will exist without an activity, so it doesn't make sense to not retain it when
its activity disappears. The given Intent here also must have an explicit ComponentName
set on it. |
description |
ActivityManager.TaskDescription :
Optional additional description information. |
thumbnail |
Bitmap :
Thumbnail to use for the recents entry. Should be the size given by
getAppTaskThumbnailSize() . If the bitmap is not that exact size, it will be
recreated in your process, probably in a way you don't like, before the recents entry
is added. |
Returns | |
---|---|
int |
Returns the task id of the newly added app task, or -1 if the add failed. The most likely cause of failure is that there is no more room for more tasks for your app. |
boolean clearApplicationUserData ()
Permits an application to erase its own data from disk. This is equivalent to the user choosing to clear the app's data from within the device settings UI. It erases all dynamic data associated with the app -- its private data and data in its private area on external storage -- but does not remove the installed application itself, nor any OBB files.
Returns | |
---|---|
boolean |
true if the application successfully requested that the application's
data be erased; false otherwise.
|
void clearWatchHeapLimit ()
Clear a heap watch limit previously set by setWatchHeapLimit(long)
.
void dumpPackageState (FileDescriptor fd, String packageName)
Perform a system dump of various state associated with the given application
package name. This call blocks while the dump is being performed, so should
not be done on a UI thread. The data will be written to the given file
descriptor as text. An application must hold the
DUMP
permission to make this call.
Parameters | |
---|---|
fd |
FileDescriptor :
The file descriptor that the dump should be written to. The file
descriptor is not closed by this function; the caller continues to
own it. |
packageName |
String :
The name of the package that is to be dumped.
|
Size getAppTaskThumbnailSize ()
Return the current design dimensions for ActivityManager.AppTask
thumbnails, for use
with addAppTask(Activity, Intent, ActivityManager.TaskDescription, Bitmap)
.
Returns | |
---|---|
Size |
List<ActivityManager.AppTask> getAppTasks ()
Get the list of tasks associated with the calling application.
Returns | |
---|---|
List<ActivityManager.AppTask> |
The list of tasks associated with the application making this call. |
Throws | |
---|---|
SecurityException |
ConfigurationInfo getDeviceConfigurationInfo ()
Get the device configuration attributes.
Returns | |
---|---|
ConfigurationInfo |
int getLargeMemoryClass ()
Return the approximate per-application memory class of the current
device when an application is running with a large heap. This is the
space available for memory-intensive applications; most applications
should not need this amount of memory, and should instead stay with the
getMemoryClass()
limit. The returned value is in megabytes.
This may be the same size as getMemoryClass()
on memory
constrained devices, or it may be significantly larger on devices with
a large amount of available RAM.
The is the size of the application's Dalvik heap if it has
specified android:largeHeap="true"
in its manifest.
Returns | |
---|---|
int |
int getLauncherLargeIconDensity ()
Get the preferred density of icons for the launcher. This is used when custom drawables are created (e.g., for shortcuts).
Returns | |
---|---|
int |
density in terms of DPI |
int getLauncherLargeIconSize ()
Get the preferred launcher icon size. This is used when custom drawables are created (e.g., for shortcuts).
Returns | |
---|---|
int |
dimensions of square icons in terms of pixels |
int getLockTaskModeState ()
Return the current state of task locking. The three possible outcomes
are LOCK_TASK_MODE_NONE
, LOCK_TASK_MODE_LOCKED
and LOCK_TASK_MODE_PINNED
.
Returns | |
---|---|
int |
See also:
int getMemoryClass ()
Return the approximate per-application memory class of the current device. This gives you an idea of how hard a memory limit you should impose on your application to let the overall system work best. The returned value is in megabytes; the baseline Android memory class is 16 (which happens to be the Java heap limit of those devices); some device with more memory may return 24 or even higher numbers.
Returns | |
---|---|
int |
void getMemoryInfo (ActivityManager.MemoryInfo outInfo)
Return general information about the memory state of the system. This
can be used to help decide how to manage your own memory, though note
that polling is not recommended and
ComponentCallbacks2.onTrimMemory(int)
is the preferred way to do this.
Also see getMyMemoryState(ActivityManager.RunningAppProcessInfo)
for how to retrieve the current trim
level of your process as needed, which gives a better hint for how to
manage its memory.
Parameters | |
---|---|
outInfo |
ActivityManager.MemoryInfo
|
void getMyMemoryState (ActivityManager.RunningAppProcessInfo outState)
Return global memory state information for the calling process. This
does not fill in all fields of the ActivityManager.RunningAppProcessInfo
. The
only fields that will be filled in are
pid
,
uid
,
lastTrimLevel
,
importance
,
lru
, and
importanceReasonCode
.
Parameters | |
---|---|
outState |
ActivityManager.RunningAppProcessInfo
|
MemoryInfo[] getProcessMemoryInfo (int[] pids)
Return information about the memory usage of one or more processes.
Note: this method is only intended for debugging or building a user-facing process management UI.
Parameters | |
---|---|
pids |
int :
The pids of the processes whose memory usage is to be
retrieved. |
Returns | |
---|---|
MemoryInfo[] |
Returns an array of memory information, one for each requested pid. |
List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState ()
Returns a list of any processes that are currently in an error condition. The result will be null if all processes are running properly at this time.
Returns | |
---|---|
List<ActivityManager.ProcessErrorStateInfo> |
Returns a list of ProcessErrorStateInfo records, or null if there are no current error conditions (it will not return an empty list). This list ordering is not specified. |
List<ActivityManager.RecentTaskInfo> getRecentTasks (int maxNum, int flags)
This method was deprecated
in API level 21.
As of LOLLIPOP
, this method is
no longer available to third party applications: the introduction of
document-centric recents means
it can leak personal information to the caller. For backwards compatibility,
it will still return a small subset of its data: at least the caller's
own tasks (though see getAppTasks()
for the correct supported
way to retrieve that information), and possibly some other tasks
such as home that are known to not be sensitive.
Note: this method is only intended for debugging and presenting task management user interfaces. This should never be used for core logic in an application, such as deciding between different behaviors based on the information found here. Such uses are not supported, and will likely break in the future. For example, if multiple applications can be actively running at the same time, assumptions made about the meaning of the data here for purposes of control flow will be incorrect.
Parameters | |
---|---|
maxNum |
int :
The maximum number of entries to return in the list. The
actual number returned may be smaller, depending on how many tasks the
user has started and the maximum number the system can remember. |
flags |
int :
Information about what to return. May be any combination
of RECENT_WITH_EXCLUDED and RECENT_IGNORE_UNAVAILABLE . |
Returns | |
---|---|
List<ActivityManager.RecentTaskInfo> |
Returns a list of RecentTaskInfo records describing each of the recent tasks. |
Throws | |
---|---|
SecurityException |
List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses ()
Returns a list of application processes that are running on the device.
Note: this method is only intended for debugging or building a user-facing process management UI.
Returns | |
---|---|
List<ActivityManager.RunningAppProcessInfo> |
Returns a list of RunningAppProcessInfo records, or null if there are no running processes (it will not return an empty list). This list ordering is not specified. |
PendingIntent getRunningServiceControlPanel (ComponentName service)
Returns a PendingIntent you can start to show a control panel for the given running service. If the service does not have a control panel, null is returned.
Parameters | |
---|---|
service |
ComponentName
|
Returns | |
---|---|
PendingIntent |
Throws | |
---|---|
SecurityException |
List<ActivityManager.RunningServiceInfo> getRunningServices (int maxNum)
Return a list of the services that are currently running.
Note: this method is only intended for debugging or implementing service management type user interfaces.
Parameters | |
---|---|
maxNum |
int :
The maximum number of entries to return in the list. The
actual number returned may be smaller, depending on how many services
are running. |
Returns | |
---|---|
List<ActivityManager.RunningServiceInfo> |
Returns a list of RunningServiceInfo records describing each of the running tasks. |
Throws | |
---|---|
SecurityException |
List<ActivityManager.RunningTaskInfo> getRunningTasks (int maxNum)
This method was deprecated
in API level 21.
As of LOLLIPOP
, this method
is no longer available to third party
applications: the introduction of document-centric recents means
it can leak person information to the caller. For backwards compatibility,
it will still retu rn a small subset of its data: at least the caller's
own tasks, and possibly some other tasks
such as home that are known to not be sensitive.
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. Note that "running" does not mean any of the task's code is currently loaded or activity -- the task may have been frozen by the system, so that it can be restarted in its previous state when next brought to the foreground.
Note: this method is only intended for debugging and presenting task management user interfaces. This should never be used for core logic in an application, such as deciding between different behaviors based on the information found here. Such uses are not supported, and will likely break in the future. For example, if multiple applications can be actively running at the same time, assumptions made about the meaning of the data here for purposes of control flow will be incorrect.
Parameters | |
---|---|
maxNum |
int :
The maximum number of entries to return in the list. The
actual number returned may be smaller, depending on how many tasks the
user has started. |
Returns | |
---|---|
List<ActivityManager.RunningTaskInfo> |
Returns a list of RunningTaskInfo records describing each of the running tasks. |
Throws | |
---|---|
SecurityException |
boolean isInLockTaskMode ()
This method was deprecated
in API level 23.
Use getLockTaskModeState()
instead.
Return whether currently in lock task mode. When in this mode no new tasks can be created or switched to.
Returns | |
---|---|
boolean |
See also:
boolean isLowRamDevice ()
Returns true if this is a low-RAM device. Exactly whether a device is low-RAM is ultimately up to the device configuration, but currently it generally means something in the class of a 512MB device with about a 800x480 or less screen. This is mostly intended to be used by apps to determine whether they should turn off certain features that require more RAM.
Returns | |
---|---|
boolean |
boolean isRunningInTestHarness ()
Returns "true" if device is running in a test harness.
Returns | |
---|---|
boolean |
boolean isUserAMonkey ()
Returns "true" if the user interface is currently being messed with by a monkey.
Returns | |
---|---|
boolean |
void killBackgroundProcesses (String packageName)
Have the system immediately kill all background processes associated with the given package. This is the same as the kernel killing those processes to reclaim memory; the system will take care of restarting these processes in the future as needed.
You must hold the permission
KILL_BACKGROUND_PROCESSES
to be able to
call this method.
Parameters | |
---|---|
packageName |
String :
The name of the package whose processes are to
be killed.
|
void moveTaskToFront (int taskId, int flags, Bundle options)
Ask that the task associated with a given task ID be moved to the
front of the stack, so it is now visible to the user. Requires that
the caller hold permission REORDER_TASKS
or a SecurityException will be thrown.
Parameters | |
---|---|
taskId |
int :
The identifier of the task to be moved, as found in
ActivityManager.RunningTaskInfo or ActivityManager.RecentTaskInfo . |
flags |
int :
Additional operational flags, 0 or more of
MOVE_TASK_WITH_HOME , MOVE_TASK_NO_USER_ACTION . |
options |
Bundle :
Additional options for the operation, either null or
as per Context.startActivity(Intent, Bundle) .
|
void moveTaskToFront (int taskId, int flags)
Equivalent to calling moveTaskToFront(int, int, Bundle)
with a null options argument.
Parameters | |
---|---|
taskId |
int :
The identifier of the task to be moved, as found in
ActivityManager.RunningTaskInfo or ActivityManager.RecentTaskInfo . |
flags |
int :
Additional operational flags, 0 or more of
MOVE_TASK_WITH_HOME , MOVE_TASK_NO_USER_ACTION .
|
void restartPackage (String packageName)
This method was deprecated
in API level 8.
This is now just a wrapper for
killBackgroundProcesses(String)
; the previous behavior here
is no longer available to applications because it allows them to
break other applications by removing their alarms, stopping their
services, etc.
Parameters | |
---|---|
packageName |
String
|
void setWatchHeapLimit (long pssSize)
Request that the system start watching for the calling process to exceed a pss
size as given here. Once called, the system will look for any occasions where it
sees the associated process with a larger pss size and, when this happens, automatically
pull a heap dump from it and allow the user to share the data. Note that this request
continues running even if the process is killed and restarted. To remove the watch,
use clearWatchHeapLimit()
.
This API only work if the calling process has been marked as
FLAG_DEBUGGABLE
or this is running on a debuggable
(userdebug or eng) build.
Callers can optionally implement ACTION_REPORT_HEAP_LIMIT
to directly
handle heap limit reports themselves.
Parameters | |
---|---|
pssSize |
long :
The size in bytes to set the limit at.
|