Using activity manager (am)
Within an adb shell, you can issue commands with the activity manager (am
) tool to perform various system actions, such as start an activity, force-stop a process, broadcast an intent, modify the device screen properties, and more. While in a shell, the syntax is:
am <command>
You can also issue an activity manager command directly from adb without entering a remote shell. For example:
adb shell am start -a android.intent.action.VIEW
Table 2. Available activity manager commands
Command | Description |
---|---|
start [options] <INTENT> | Start an Activity specified by<INTENT> . See the Specification for <INTENT> arguments. Options are:
|
startservice [options] <INTENT> | Start the Service specified by<INTENT> . See the Specification for <INTENT> arguments. Options are:
|
force-stop <PACKAGE> | Force stop everything associated with <PACKAGE> (the app's package name). |
kill [options] <PACKAGE> | Kill all processes associated with <PACKAGE> (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience. Options are:
|
kill-all | Kill all background processes. |
broadcast [options] <INTENT> | Issue a broadcast intent. See the Specification for <INTENT> arguments. Options are:
|
instrument [options] <COMPONENT> | Start monitoring with an Instrumentation instance. Typically the target<COMPONENT> is the form <TEST_PACKAGE>/<RUNNER_CLASS> . Options are:
|
profile start <PROCESS> <FILE> | Start profiler on <PROCESS> , write results to <FILE> . |
profile stop <PROCESS> | Stop profiler on <PROCESS> . |
dumpheap [options] <PROCESS> <FILE> | Dump the heap of <PROCESS> , write to <FILE> . Options are:
|
set-debug-app [options] <PACKAGE> | Set application <PACKAGE> to debug. Options are:
|
clear-debug-app | Clear the package previous set for debugging with set-debug-app . |
monitor [options] | Start monitoring for crashes or ANRs. Options are:
|
screen-compat [on|off] <PACKAGE> | Control screen compatibility mode of <PACKAGE> . |
display-size [reset|<WxH>] | Override emulator/device display size. This command is helpful for testing your app across different screen sizes by mimicking a small screen resolution using a device with a large screen, and vice versa. Example: |
display-density <dpi> | Override emulator/device display density. This command is helpful for testing your app across different screen densities on high-density screen environment using a low density screen, and vice versa. Example: |
to-uri <INTENT> | Print the given intent specification as a URI. See the Specification for <INTENT> arguments. |
to-intent-uri <INTENT> | Print the given intent specification as an intent: URI. See the Specification for <INTENT> arguments. |
Specification for <INTENT> arguments
For activity manager commands that take a <INTENT>
argument, you can specify the intent with the following options:
- Specify the intent action, such as "android.intent.action.VIEW". You can declare this only once.
- Specify the intent data URI, such as "content://contacts/people/1". You can declare this only once.
- Specify the intent MIME type, such as "image/png". You can declare this only once.
- Specify an intent category, such as "android.intent.category.APP_CONTACTS".
- Specify the component name with package name prefix to create an explicit intent, such as "com.example.app/.ExampleActivity".
-
Add flags to the intent, as supported by
setFlags()
. - Add a null extra. This option is not supported for URI intents.
- Add string data as a key-value pair.
- Add boolean data as a key-value pair.
- Add integer data as a key-value pair.
- Add long data as a key-value pair.
- Add float data as a key-value pair.
- Add URI data as a key-value pair.
-
Add a component name, which is converted and passed as a
ComponentName
object. - Add an array of integers.
- Add an array of longs.
- Add an array of floats.
-
Include the flag
FLAG_GRANT_READ_URI_PERMISSION
. -
Include the flag
FLAG_GRANT_WRITE_URI_PERMISSION
. -
Include the flag
FLAG_DEBUG_LOG_RESOLUTION
. -
Include the flag
FLAG_EXCLUDE_STOPPED_PACKAGES
. -
Include the flag
FLAG_INCLUDE_STOPPED_PACKAGES
. -
Include the flag
FLAG_ACTIVITY_BROUGHT_TO_FRONT
. -
Include the flag
FLAG_ACTIVITY_CLEAR_TOP
. -
Include the flag
FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
. -
Include the flag
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
. -
Include the flag
FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
. -
Include the flag
FLAG_ACTIVITY_MULTIPLE_TASK
. -
Include the flag
FLAG_ACTIVITY_NO_ANIMATION
. -
Include the flag
FLAG_ACTIVITY_NO_HISTORY
. -
Include the flag
FLAG_ACTIVITY_NO_USER_ACTION
. -
Include the flag
FLAG_ACTIVITY_PREVIOUS_IS_TOP
. -
Include the flag
FLAG_ACTIVITY_REORDER_TO_FRONT
. -
Include the flag
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
. -
Include the flag
FLAG_ACTIVITY_SINGLE_TOP
. -
Include the flag
FLAG_ACTIVITY_CLEAR_TASK
. -
Include the flag
FLAG_ACTIVITY_TASK_ON_HOME
. -
Include the flag
FLAG_RECEIVER_REGISTERED_ONLY
. -
Include the flag
FLAG_RECEIVER_REPLACE_PENDING
. -
Requires the use of
-d
and-t
options to set the intent data and type. - You can directly specify a URI, package name, and component name when not qualified by one of the above options. When an argument is unqualified, the tool assumes the argument is a URI if it contains a ":" (colon); it assumes the argument is a component name if it contains a "/" (forward-slash); otherwise it assumes the argument is a package name.
-a <ACTION>
-d <DATA_URI>
-t <MIME_TYPE>
-c <CATEGORY>
-n <COMPONENT>
-f <FLAGS>
--esn <EXTRA_KEY>
-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>
--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>
--ei <EXTRA_KEY> <EXTRA_INT_VALUE>
--el <EXTRA_KEY> <EXTRA_LONG_VALUE>
--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE>
--eu <EXTRA_KEY> <EXTRA_URI_VALUE>
--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>
--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]
--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]
--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]
--grant-read-uri-permission
--grant-write-uri-permission
--debug-log-resolution
--exclude-stopped-packages
--include-stopped-packages
--activity-brought-to-front
--activity-clear-top
--activity-clear-when-task-reset
--activity-exclude-from-recents
--activity-launched-from-history
--activity-multiple-task
--activity-no-animation
--activity-no-history
--activity-no-user-action
--activity-previous-is-top
--activity-reorder-to-front
--activity-reset-task-if-needed
--activity-single-top
--activity-clear-task
--activity-task-on-home
--receiver-registered-only
--receiver-replace-pending
--selector
<URI> <COMPONENT> <PACKAGE>