In-depth Analysis of Launching Android Settings via ADB: From Monkey Commands to Correct Usage of Activity Manager

Dec 11, 2025 · Programming · 9 views · 7.8

Keywords: ADB Commands | Android Settings Launch | Activity Manager

Abstract: This article addresses the "Killed" error encountered by developers when launching Android settings via ADB, providing a thorough analysis of the limitations of the adb shell monkey command and detailing the correct approach using adb shell am start. By comparing the working principles of both commands, it explains why monkey commands may fail in certain scenarios, offering complete code examples and debugging techniques to help developers efficiently resolve similar issues.

Problem Background and Phenomenon Analysis

In Android development and testing, developers often need to remotely launch applications on devices via ADB (Android Debug Bridge). A common requirement is to start the system settings app, for instance, to enable MTP (Media Transfer Protocol) mode for connecting the device to a computer. The user initially attempted the following command:

adb shell monkey -p com.android.settings -c android.intent.category.LAUNCHER 1

However, the terminal consistently output "Killed" after each execution, even after attempting to restart ADB, obtain root privileges, or reboot the device. Further testing revealed that this issue was not limited to the settings app; other application package names exhibited the same behavior.

Working Principles and Limitations of Monkey Commands

The adb shell monkey command is a UI/application testing tool provided by Android, primarily designed to generate pseudo-random user event streams (e.g., clicks, swipes). The -p parameter specifies the target application package name, and the -c parameter specifies the Intent category. However, monkey is essentially a stress-testing tool, not specifically intended for launching particular Activities. When using -c android.intent.category.LAUNCHER, monkey attempts to send a launch Intent to the system, but this approach may lead to process termination by the system due to permissions, security policies, or Intent resolution issues on certain Android versions or device configurations, resulting in the "Killed" message.

Correct Solution: Using Activity Manager Commands

Android provides a more direct method for launching application components: the Activity Manager (am). Through the adb shell am start command, developers can precisely control Intent launch parameters. For launching the settings app, the correct command is:

adb shell am start -a android.settings.SETTINGS

Here, the -a parameter specifies the Intent Action. android.settings.SETTINGS is a system-predefined Action constant specifically for launching the main settings interface. Compared to the monkey command, am start interacts directly with the system Activity Manager, avoiding unnecessary testing framework overhead, thus proving more reliable.

Code Examples and In-depth Analysis

To aid understanding, we reimplement a simplified launch script. The following code demonstrates how to use am start to launch different settings sub-interfaces:

#!/bin/bash
# Launch developer options settings
adb shell am start -a com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS

# Launch Wi-Fi settings
adb shell am start -a android.settings.WIFI_SETTINGS

# Launch Bluetooth settings
adb shell am start -a android.settings.BLUETOOTH_SETTINGS

Each -a parameter corresponds to a specific Intent Action, defined within the Android framework to ensure the system correctly parses and launches the corresponding Activity. Developers can find more available Actions using commands like:

adb shell dumpsys | grep "SETTINGS"

Debugging Techniques and Considerations

If the am start command also fails, debug using the following steps:

  1. Check device connection: Use adb devices to ensure the device is properly connected.
  2. View logs: Run adb logcat | grep ActivityManager to observe error messages during the launch process.
  3. Verify package name: Ensure the application package name is correct; for system apps like settings, it is typically com.android.settings.
  4. Permission issues: Some settings interfaces may require special permissions and might not launch on non-root devices.

Note that different Android versions may support different Intent Actions. For example, older Gingerbread systems use com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS for developer options, while newer versions might have changes.

Summary and Best Practices

When launching Android applications via ADB, prioritize using adb shell am start over adb shell monkey. am start offers more precise Intent control, avoiding the testing framework limitations of monkey commands. For settings apps, using predefined Action constants like android.settings.SETTINGS ensures compatibility. Developers should familiarize themselves with common Intent Actions and combine them with logging debugging tools to resolve launch issues, thereby improving development efficiency.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.