public class

ActivityManager

extends Object
java.lang.Object
   ↳ android.app.ActivityManager

Class Overview

Interact with the overall activities running in the system.

Summary

Nested Classes
class ActivityManager.MemoryInfo Information you can retrieve about the available memory through getMemoryInfo(ActivityManager.MemoryInfo)
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. 
Constants
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.
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 getRecentTasks(int, int): return all tasks, even those that have set their FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS flag.
Public Methods
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 getMemoryClass()
Return the approximate per-application memory class of the current device.
void getMemoryInfo(ActivityManager.MemoryInfo outInfo)
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)
Return a list of the tasks that the user has recently launched, with the most recent being first and older ones after in order.
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)
Return a list of the tasks that are currently running, with the most recent being first and older ones after in order.
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)
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 restartPackage(String packageName)
This method is deprecated. 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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int MOVE_TASK_WITH_HOME

Since: API Level 11

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)

public static final int RECENT_IGNORE_UNAVAILABLE

Since: API Level 11

Provides a list that does not contain any recent tasks that currently are not available to the user.

Constant Value: 2 (0x00000002)

public static final int RECENT_WITH_EXCLUDED

Since: API Level 1

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)

Public Methods

public ConfigurationInfo getDeviceConfigurationInfo ()

Since: API Level 3

Get the device configuration attributes.

public int getLargeMemoryClass ()

Since: API Level 11

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.

public int getLauncherLargeIconDensity ()

Since: API Level 11

Get the preferred density of icons for the launcher. This is used when custom drawables are created (e.g., for shortcuts).

Returns
  • density in terms of DPI

public int getLauncherLargeIconSize ()

Since: API Level 11

Get the preferred launcher icon size. This is used when custom drawables are created (e.g., for shortcuts).

Returns
  • dimensions of square icons in terms of pixels

public int getMemoryClass ()

Since: API Level 5

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.

public void getMemoryInfo (ActivityManager.MemoryInfo outInfo)

Since: API Level 1

public MemoryInfo[] getProcessMemoryInfo (int[] pids)

Since: API Level 5

Return information about the memory usage of one or more processes.

Parameters
pids The pids of the processes whose memory usage is to be retrieved.
Returns
  • Returns an array of memory information, one for each requested pid.

public List<ActivityManager.ProcessErrorStateInfo> getProcessesInErrorState ()

Since: API Level 1

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
  • 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.

public List<ActivityManager.RecentTaskInfo> getRecentTasks (int maxNum, int flags)

Since: API Level 1

Return a list of the tasks that the user has recently launched, with the most recent being first and older ones after in order.

Parameters
maxNum 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 Information about what to return. May be any combination of RECENT_WITH_EXCLUDED and RECENT_IGNORE_UNAVAILABLE.
Returns
  • Returns a list of RecentTaskInfo records describing each of the recent tasks.
Throws
SecurityException Throws SecurityException if the caller does not hold the GET_TASKS permission.

public List<ActivityManager.RunningAppProcessInfo> getRunningAppProcesses ()

Since: API Level 3

Returns a list of application processes that are running on the device.

Returns
  • 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.

public PendingIntent getRunningServiceControlPanel (ComponentName service)

Since: API Level 5

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.

public List<ActivityManager.RunningServiceInfo> getRunningServices (int maxNum)

Since: API Level 1

Return a list of the services that are currently running.

Parameters
maxNum 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
  • Returns a list of RunningServiceInfo records describing each of the running tasks.

public List<ActivityManager.RunningTaskInfo> getRunningTasks (int maxNum)

Since: API Level 1

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.

Parameters
maxNum 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
  • Returns a list of RunningTaskInfo records describing each of the running tasks.
Throws
SecurityException Throws SecurityException if the caller does not hold the GET_TASKS permission.

public static boolean isRunningInTestHarness ()

Since: API Level 11

Returns "true" if device is running in a test harness.

public static boolean isUserAMonkey ()

Since: API Level 8

Returns "true" if the user interface is currently being messed with by a monkey.

public void killBackgroundProcesses (String packageName)

Since: API Level 8

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 The name of the package whose processes are to be killed.

public void moveTaskToFront (int taskId, int flags)

Since: API Level 11

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 The identifier of the task to be moved, as found in ActivityManager.RunningTaskInfo or ActivityManager.RecentTaskInfo.
flags Additional operational flags, 0 or more of MOVE_TASK_WITH_HOME.

public void restartPackage (String packageName)

Since: API Level 3

This method is deprecated.
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.