ActivityManager
open class ActivityManager
kotlin.Any | |
↳ | android.app.ActivityManager |
This class gives information about, and interacts with, activities, services, and the containing process.
A number of the methods in this class are for debugging or informational purposes and they should not be used to affect any runtime behavior of your app. These methods are called out as such in the method level documentation.
Most application developers should not have the need to use this class, most of whose methods are for specialized use cases. However, a few methods are more broadly applicable. For instance, isLowRamDevice()
enables your app to detect whether it is running on a low-memory device, and behave accordingly. clearApplicationUserData()
is for apps with reset-data functionality.
In some special use cases, where an app interacts with its Task stack, the app may use the android.app.ActivityManager.AppTask
and android.app.ActivityManager.RecentTaskInfo
inner classes. However, in general, the methods in this class should be used for testing and debugging purposes only.
Summary
Nested classes | |
---|---|
open |
The AppTask allows you to manage your own application's tasks. |
open |
Information you can retrieve about the available memory through |
open |
Information you can retrieve about any processes that are in an error condition. |
open |
Information you can retrieve about tasks that the user has most recently started or visited. |
open |
Information you can retrieve about a running process. |
open |
Information you can retrieve about a particular Service that is currently running in the system. |
open |
Information you can retrieve about a particular task that is currently "running" in the system. |
open |
Information you can set and retrieve about the current activity within the recent task list. |
Constants | |
---|---|
static String |
Action an app can implement to handle reports from |
static Int |
Full lock task mode is active. |
static Int |
Lock task mode is not active. |
static Int |
App pinning mode is active. |
static String |
|
static Int |
Flag for |
static Int |
Flag for |
static Int |
Provides a list that does not contain any recent tasks that currently are not available to the user. |
static Int |
Flag for use with |
Public methods | |
---|---|
open Int |
addAppTask(activity: Activity, intent: Intent, description: ActivityManager.TaskDescription?, thumbnail: Bitmap) Add a new |
open Unit |
addApplicationStartInfoCompletionListener(executor: Executor, listener: Consumer<ApplicationStartInfo!>) Adds a callback that is notified when the |
open Unit |
addStartInfoTimestamp(key: Int, timestampNs: Long) Adds an optional developer supplied timestamp to the calling apps most recent |
open Unit |
appNotResponding(reason: String) Method for the app to tell system that it's wedged and would like to trigger an ANR. |
open Boolean |
Permits an application to erase its own data from disk. |
open Unit |
Clear a heap watch limit previously set by |
open Unit |
dumpPackageState(fd: FileDescriptor!, packageName: String!) Perform a system dump of various state associated with the given application package name. |
open Size! |
Return the current design dimensions for |
open MutableList<ActivityManager.AppTask!>! |
Get the list of tasks associated with the calling application. |
open ConfigurationInfo! |
Get the device configuration attributes. |
open MutableList<ApplicationExitInfo!> |
getHistoricalProcessExitReasons(packageName: String?, pid: Int, maxNum: Int) Return a list of |
open MutableList<ApplicationStartInfo!> |
getHistoricalProcessStartReasons(maxNum: Int) Return a list of |
open Int |
Return the approximate per-application memory class of the current device when an application is running with a large heap. |
open Int |
Get the preferred density of icons for the launcher. |
open Int |
Get the preferred launcher icon size. |
open Int |
Return the current state of task locking. |
open Int |
Return the approximate per-application memory class of the current device. |
open Unit |
getMemoryInfo(outInfo: ActivityManager.MemoryInfo!) Return general information about the memory state of the system. |
open static Unit |
Return global memory state information for the calling process. |
open Array<Debug.MemoryInfo!>! |
getProcessMemoryInfo(pids: IntArray!) Return information about the memory usage of one or more processes. |
open MutableList<ActivityManager.ProcessErrorStateInfo!>! |
Returns a list of any processes that are currently in an error condition. |
open MutableList<ActivityManager.RecentTaskInfo!>! |
getRecentTasks(maxNum: Int, flags: Int) |
open MutableList<ActivityManager.RunningAppProcessInfo!>! |
Returns a list of application processes that are running on the device. |
open PendingIntent! |
getRunningServiceControlPanel(service: ComponentName!) Returns a PendingIntent you can start to show a control panel for the given running service. |
open MutableList<ActivityManager.RunningServiceInfo!>! |
getRunningServices(maxNum: Int) Return a list of the services that are currently running. |
open MutableList<ActivityManager.RunningTaskInfo!>! |
getRunningTasks(maxNum: Int) Return a list of the tasks that are currently running, with the most recent being first and older ones after in order. |
open Boolean |
isActivityStartAllowedOnDisplay(context: Context, displayId: Int, intent: Intent) Check if the context is allowed to start an activity on specified display. |
open Boolean |
Query whether the user has enabled background restrictions for this app. |
open Boolean |
Return whether currently in lock task mode. |
open static Boolean | |
open Boolean |
Returns true if this is a low-RAM device. |
open static Boolean |
Returns "true" if device is running in a test harness. |
open static Boolean |
Returns "true" if the device is running in Test Harness Mode. |
open static Boolean |
Returns "true" if the user interface is currently being messed with by a monkey. |
open Unit |
killBackgroundProcesses(packageName: String!) Have the system immediately kill all background processes associated with the given package. |
open Unit |
moveTaskToFront(taskId: Int, flags: Int) Equivalent to calling |
open Unit |
moveTaskToFront(taskId: Int, flags: Int, options: Bundle!) 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. |
open Unit |
Removes the provided callback set by |
open Unit |
restartPackage(packageName: String!) |
open Unit |
setProcessStateSummary(state: ByteArray?) Set custom state data for this process. |
open static Unit |
setVrThread(tid: Int) Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. |
open Unit |
setWatchHeapLimit(pssSize: Long) Request that the system start watching for the calling process to exceed a pss size as given here. |
Constants
ACTION_REPORT_HEAP_LIMIT
static val ACTION_REPORT_HEAP_LIMIT: String
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 Intent#ACTION_SEND
. Note that to match, the activity must support this action and a MIME type of "*/*".
Value: "android.app.action.REPORT_HEAP_LIMIT"
LOCK_TASK_MODE_LOCKED
static val LOCK_TASK_MODE_LOCKED: Int
Full lock task mode is active.
Value: 1
LOCK_TASK_MODE_NONE
static val LOCK_TASK_MODE_NONE: Int
Lock task mode is not active.
Value: 0
LOCK_TASK_MODE_PINNED
static val LOCK_TASK_MODE_PINNED: Int
App pinning mode is active.
Value: 2
META_HOME_ALTERNATE
static val META_HOME_ALTERNATE: String
<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>
.
Value: "android.app.home.alternate"
MOVE_TASK_NO_USER_ACTION
static val MOVE_TASK_NO_USER_ACTION: Int
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.
Value: 2
MOVE_TASK_WITH_HOME
static val MOVE_TASK_WITH_HOME: Int
Flag for moveTaskToFront(int,int)
: also move the "home" activity along with the task, so it is positioned immediately behind the task.
Value: 1
RECENT_IGNORE_UNAVAILABLE
static val RECENT_IGNORE_UNAVAILABLE: Int
Provides a list that does not contain any recent tasks that currently are not available to the user.
Value: 2
RECENT_WITH_EXCLUDED
static val RECENT_WITH_EXCLUDED: Int
Flag for use with getRecentTasks
: return all tasks, even those that have set their android.content.Intent#FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
flag.
Value: 1
Public methods
addAppTask
open fun addAppTask(
activity: Activity,
intent: Intent,
description: ActivityManager.TaskDescription?,
thumbnail: Bitmap
): Int
Add a new 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. This value cannot be null . |
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 Intent#FLAG_ACTIVITY_NEW_DOCUMENT and Intent#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. This value cannot be null . |
description |
ActivityManager.TaskDescription?: Optional additional description information. This value may be null . |
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. This value cannot be null . |
Return | |
---|---|
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. |
addApplicationStartInfoCompletionListener
open fun addApplicationStartInfoCompletionListener(
executor: Executor,
listener: Consumer<ApplicationStartInfo!>
): Unit
Adds a callback that is notified when the ApplicationStartInfo
record of this startup is complete. The startup is considered complete when the first frame is drawn. The callback doesn't wait for Activity#reportFullyDrawn
to occur. Retrieve a copy of ApplicationStartInfo
after Activity#reportFullyDrawn
is called (using this callback or getHistoricalProcessStartReasons) if you need the ApplicationStartInfo.START_TIMESTAMP_FULLY_DRAWN timestamp. If the current start record has already been completed (that is, the process is not currently starting), the callback will be invoked immediately on the specified executor with the previously completed ApplicationStartInfo
record. Callback will be called at most once and removed automatically after being triggered.
Note: callback is asynchronous and should be made from a background thread.
Parameters | |
---|---|
executor |
Executor: The executor on which the listener should be called. This value cannot be null . |
listener |
Consumer<ApplicationStartInfo!>: Callback to be called when collection of ApplicationStartInfo is complete. Will replace existing listener if one is already attached. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if executor or listener are null. |
addStartInfoTimestamp
open fun addStartInfoTimestamp(
key: Int,
timestampNs: Long
): Unit
Adds an optional developer supplied timestamp to the calling apps most recent ApplicationStartInfo
. This is in addition to system recorded timestamps.
Note: any timestamps added after Activity#reportFullyDrawn
is called are discarded.
Note: will overwrite existing timestamp if called with same key.
Parameters | |
---|---|
key |
Int: Unique key for timestamp. Must be greater than ApplicationStartInfo#START_TIMESTAMP_RESERVED_RANGE_SYSTEM and less than or equal to ApplicationStartInfo#START_TIMESTAMP_RESERVED_RANGE_DEVELOPER . Will thow java.lang.IllegalArgumentException if not in range. Value is between ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER_START and ApplicationStartInfo.START_TIMESTAMP_RESERVED_RANGE_DEVELOPER inclusive |
timestampNs |
Long: Clock monotonic time in nanoseconds of event to be recorded. |
appNotResponding
open fun appNotResponding(reason: String): Unit
Method for the app to tell system that it's wedged and would like to trigger an ANR.
Parameters | |
---|---|
reason |
String: The description of that what happened This value cannot be null . |
clearApplicationUserData
open fun clearApplicationUserData(): Boolean
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. It also revokes all runtime permissions that the app has acquired, clears all notifications and removes all Uri grants related to this application.
Return | |
---|---|
Boolean |
true if the application successfully requested that the application's data be erased; false otherwise. |
clearWatchHeapLimit
open fun clearWatchHeapLimit(): Unit
Clear a heap watch limit previously set by setWatchHeapLimit(long)
.
dumpPackageState
open fun dumpPackageState(
fd: FileDescriptor!,
packageName: String!
): Unit
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.
Requires android.Manifest.permission#DUMP
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. |
getAppTaskThumbnailSize
open fun getAppTaskThumbnailSize(): Size!
Return the current design dimensions for AppTask
thumbnails, for use with addAppTask
.
getAppTasks
open fun getAppTasks(): MutableList<ActivityManager.AppTask!>!
Get the list of tasks associated with the calling application.
Return | |
---|---|
MutableList<ActivityManager.AppTask!>! |
The list of tasks associated with the application making this call. |
Exceptions | |
---|---|
java.lang.SecurityException |
getDeviceConfigurationInfo
open fun getDeviceConfigurationInfo(): ConfigurationInfo!
Get the device configuration attributes.
getHistoricalProcessExitReasons
open fun getHistoricalProcessExitReasons(
packageName: String?,
pid: Int,
maxNum: Int
): MutableList<ApplicationExitInfo!>
Return a list of ApplicationExitInfo
records containing the reasons for the most recent app deaths.
Note: System stores this historical information in a ring buffer and only the most recent records will be returned.
Note: In the case that this application was bound to an external service with flag android.content.Context#BIND_EXTERNAL_SERVICE
, the process of that external service will be included in this package's exit info.
Parameters | |
---|---|
packageName |
String?: Optional, a null value means match all packages belonging to the caller's UID. If this package belongs to another UID, you must hold android.Manifest.permission#DUMP in order to retrieve it. |
pid |
Int: A process ID that used to belong to this package but died later; a value of 0 means to ignore this parameter and return all matching records. Value is 0 or greater |
maxNum |
Int: The maximum number of results to be returned; a value of 0 means to ignore this parameter and return all matching records Value is 0 or greater |
Return | |
---|---|
MutableList<ApplicationExitInfo!> |
a list of ApplicationExitInfo records matching the criteria, sorted in the order from most recent to least recent. This value cannot be null . |
getHistoricalProcessStartReasons
open fun getHistoricalProcessStartReasons(maxNum: Int): MutableList<ApplicationStartInfo!>
Return a list of ApplicationStartInfo
records containing the information about the most recent app startups. Records accessed using this path might include "incomplete" records such as in-progress app starts. Accessing in-progress starts using this method lets you access start information early to better optimize your startup path.
Note: System stores this historical information in a ring buffer and only the most recent records will be returned.
Parameters | |
---|---|
maxNum |
Int: The maximum number of results to be returned; a value of 0 means to ignore this parameter and return all matching records. If fewer records exist, all existing records will be returned. Value is 0 or greater |
Return | |
---|---|
MutableList<ApplicationStartInfo!> |
a list of ApplicationStartInfo records matching the criteria, sorted in the order from most recent to least recent. This value cannot be null . |
getLargeMemoryClass
open fun getLargeMemoryClass(): Int
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.
This is the size of the application's Dalvik heap if it has specified android:largeHeap="true"
in its manifest.
getLauncherLargeIconDensity
open fun getLauncherLargeIconDensity(): Int
Get the preferred density of icons for the launcher. This is used when custom drawables are created (e.g., for shortcuts).
Return | |
---|---|
Int |
density in terms of DPI |
getLauncherLargeIconSize
open fun getLauncherLargeIconSize(): Int
Get the preferred launcher icon size. This is used when custom drawables are created (e.g., for shortcuts).
Return | |
---|---|
Int |
dimensions of square icons in terms of pixels |
getLockTaskModeState
open fun getLockTaskModeState(): Int
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
.
See Also
getMemoryClass
open fun getMemoryClass(): Int
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 devices with more memory may return 24 or even higher numbers.
getMemoryInfo
open fun getMemoryInfo(outInfo: ActivityManager.MemoryInfo!): Unit
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
for how to retrieve the current trim level of your process as needed, which gives a better hint for how to manage its memory.
getMyMemoryState
open static fun getMyMemoryState(outState: ActivityManager.RunningAppProcessInfo!): Unit
Return global memory state information for the calling process. This does not fill in all fields of the RunningAppProcessInfo
. The only fields that will be filled in are RunningAppProcessInfo#pid
, RunningAppProcessInfo#uid
, RunningAppProcessInfo#lastTrimLevel
, RunningAppProcessInfo#importance
, RunningAppProcessInfo#lru
, and RunningAppProcessInfo#importanceReasonCode
.
getProcessMemoryInfo
open fun getProcessMemoryInfo(pids: IntArray!): Array<Debug.MemoryInfo!>!
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.
As of Android Q
, for regular apps this method will only return information about the memory info for the processes running as the caller's uid; no other process memory info is available and will be zero. Also of Android Q
the sample rate allowed by this API is significantly limited, if called faster the limit you will receive the same data as the previous call.
Parameters | |
---|---|
pids |
IntArray!: The pids of the processes whose memory usage is to be retrieved. |
Return | |
---|---|
Array<Debug.MemoryInfo!>! |
Returns an array of memory information, one for each requested pid. |
getProcessesInErrorState
open fun getProcessesInErrorState(): MutableList<ActivityManager.ProcessErrorStateInfo!>!
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.
As of Android TIRAMISU
, for regular apps this method will only return ProcessErrorStateInfo
records for the processes running as the caller's uid, unless the caller has the permission android.Manifest.permission#DUMP
.
Return | |
---|---|
MutableList<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. |
getRecentTasks
open fungetRecentTasks(
maxNum: Int,
flags: Int
): MutableList<ActivityManager.RecentTaskInfo!>!
Deprecated: As of android.os.Build.VERSION_CODES#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 . |
Return | |
---|---|
MutableList<ActivityManager.RecentTaskInfo!>! |
Returns a list of RecentTaskInfo records describing each of the recent tasks. |
getRunningAppProcesses
open fun getRunningAppProcesses(): MutableList<ActivityManager.RunningAppProcessInfo!>!
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.
Return | |
---|---|
MutableList<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. |
getRunningServiceControlPanel
open fun getRunningServiceControlPanel(service: ComponentName!): PendingIntent!
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.
getRunningServices
open fungetRunningServices(maxNum: Int): MutableList<ActivityManager.RunningServiceInfo!>!
Deprecated: As of android.os.Build.VERSION_CODES#O
, this method is no longer available to third party applications. For backwards compatibility, it will still return the caller's own services.
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. |
Return | |
---|---|
MutableList<ActivityManager.RunningServiceInfo!>! |
Returns a list of RunningServiceInfo records describing each of the running tasks. |
getRunningTasks
open fungetRunningTasks(maxNum: Int): MutableList<ActivityManager.RunningTaskInfo!>!
Deprecated: As of android.os.Build.VERSION_CODES#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 return 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. |
Return | |
---|---|
MutableList<ActivityManager.RunningTaskInfo!>! |
Returns a list of RunningTaskInfo records describing each of the running tasks. |
isActivityStartAllowedOnDisplay
open fun isActivityStartAllowedOnDisplay(
context: Context,
displayId: Int,
intent: Intent
): Boolean
Check if the context is allowed to start an activity on specified display. Some launch restrictions may apply to secondary displays that are private, virtual, or owned by the system, in which case an activity start may throw a SecurityException
. Call this method prior to starting an activity on a secondary display to check if the current context has access to it.
Parameters | |
---|---|
context |
Context: Source context, from which an activity will be started. This value cannot be null . |
displayId |
Int: Target display id. |
intent |
Intent: Intent used to launch an activity. This value cannot be null . |
Return | |
---|---|
Boolean |
true if a call to start an activity on the target display is allowed for the provided context and no SecurityException will be thrown, false otherwise. |
isBackgroundRestricted
open fun isBackgroundRestricted(): Boolean
Query whether the user has enabled background restrictions for this app.
The user may chose to do this, if they see that an app is consuming an unreasonable amount of battery while in the background.
If true, any work that the app tries to do will be aggressively restricted while it is in the background. At a minimum, jobs and alarms will not execute and foreground services cannot be started unless an app activity is in the foreground.
Note that these restrictions stay in effect even when the device is charging.
Return | |
---|---|
Boolean |
true if user has enforced background restrictions for this app, false otherwise. |
isInLockTaskMode
open funisInLockTaskMode(): Boolean
Deprecated: Use getLockTaskModeState
instead.
Return whether currently in lock task mode. When in this mode no new tasks can be created or switched to.
See Also
isLowMemoryKillReportSupported
open static fun isLowMemoryKillReportSupported(): Boolean
Return | |
---|---|
Boolean |
Whether or not the low memory kill will be reported in getHistoricalProcessExitReasons . |
isLowRamDevice
open fun isLowRamDevice(): Boolean
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 with 1GB or less of RAM. This is mostly intended to be used by apps to determine whether they should turn off certain features that require more RAM.
isRunningInTestHarness
open static funisRunningInTestHarness(): Boolean
Deprecated: this method is false for all user builds. Users looking to check if their device is running in a device farm should see isRunningInUserTestHarness()
.
Returns "true" if device is running in a test harness.
isRunningInUserTestHarness
open static fun isRunningInUserTestHarness(): Boolean
Returns "true" if the device is running in Test Harness Mode.
Test Harness Mode is a feature that allows devices to run without human interaction in a device farm/testing harness (such as Firebase Test Lab). You should check this method if you want your app to behave differently when running in a test harness to skip setup screens that would impede UI testing. e.g. a keyboard application that has a full screen setup page for the first time it is launched.
Note that you should not use this to determine whether or not your app is running an instrumentation test, as it is not set for a standard device running a test.
isUserAMonkey
open static fun isUserAMonkey(): Boolean
Returns "true" if the user interface is currently being messed with by a monkey.
killBackgroundProcesses
open fun killBackgroundProcesses(packageName: String!): Unit
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.
On devices that run Android 14 or higher, third party applications can only use this API to kill their own processes.
Requires
android.Manifest.permission#KILL_BACKGROUND_PROCESSES
Parameters | |
---|---|
packageName |
String!: The name of the package whose processes are to be killed. |
moveTaskToFront
open fun moveTaskToFront(
taskId: Int,
flags: Int
): Unit
Equivalent to calling moveTaskToFront(int,int,android.os.Bundle)
with a null options argument.
Requires android.Manifest.permission#REORDER_TASKS
Parameters | |
---|---|
taskId |
Int: The identifier of the task to be moved, as found in RunningTaskInfo or RecentTaskInfo . |
flags |
Int: Additional operational flags. Value is either 0 or a combination of android.app.ActivityManager#MOVE_TASK_WITH_HOME , and android.app.ActivityManager#MOVE_TASK_NO_USER_ACTION |
moveTaskToFront
open fun moveTaskToFront(
taskId: Int,
flags: Int,
options: Bundle!
): Unit
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 android.Manifest.permission#REORDER_TASKS
Parameters | |
---|---|
taskId |
Int: The identifier of the task to be moved, as found in RunningTaskInfo or RecentTaskInfo . |
flags |
Int: Additional operational flags. Value is either 0 or a combination of android.app.ActivityManager#MOVE_TASK_WITH_HOME , and android.app.ActivityManager#MOVE_TASK_NO_USER_ACTION |
options |
Bundle!: Additional options for the operation, either null or as per Context.startActivity(Intent, Bundle) . |
removeApplicationStartInfoCompletionListener
open fun removeApplicationStartInfoCompletionListener(listener: Consumer<ApplicationStartInfo!>): Unit
Removes the provided callback set by addApplicationStartInfoCompletionListener
.
Parameters | |
---|---|
listener |
Consumer<ApplicationStartInfo!>: This value cannot be null . |
restartPackage
open funrestartPackage(packageName: String!): Unit
Deprecated: This is now just a wrapper for killBackgroundProcesses(java.lang.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.
setProcessStateSummary
open fun setProcessStateSummary(state: ByteArray?): Unit
Set custom state data for this process. It will be included in the record of ApplicationExitInfo
on the death of the current calling process; the new process of the app can retrieve this state data by calling ApplicationExitInfo.getProcessStateSummary()
on the record returned by getHistoricalProcessExitReasons
.
This would be useful for the calling app to save its stateful data: if it's killed later for any reason, the new process of the app can know what the previous process of the app was doing. For instance, you could use this to encode the current level in a game, or a set of features/experiments that were enabled. Later you could analyze under what circumstances the app tends to crash or use too much memory. However, it's not suggested to rely on this to restore the applications previous UI state or so, it's only meant for analyzing application healthy status.
System might decide to throttle the calls to this API; so call this API in a reasonable manner, excessive calls to this API could result a java.lang.RuntimeException
.
Parameters | |
---|---|
state |
ByteArray?: The state data. To be advised, DO NOT include sensitive information/data (PII, SPII, or other sensitive user data) here. Maximum length is 128 bytes. This value may be null . |
setVrThread
open static fun setVrThread(tid: Int): Unit
Enable more aggressive scheduling for latency-sensitive low-runtime VR threads. Only one thread can be a VR thread in a process at a time, and that thread may be subject to restrictions on the amount of time it can run. If persistent VR mode is set, whatever thread has been granted aggressive scheduling via this method will return to normal operation, and calling this method will do nothing while persistent VR mode is enabled. To reset the VR thread for an application, a tid of 0 can be passed.
Parameters | |
---|---|
tid |
Int: tid of the VR thread |
See Also
setWatchHeapLimit
open fun setWatchHeapLimit(pssSize: Long): Unit
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 works if the calling process has been marked as ApplicationInfo#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. |