Background apps and processes are essential to the proper functioning of an Android device. Some apps run in the foreground and are noticeable to users, while others run stealthily in the background. This tutorial will explore all working ADB commands that let you check apps running in the background and foreground on Android devices. Once you have the list of running apps and processes, their PID, and CPU and memory usage, you can identify the ones that need to be stopped.
Among several things ADB can do on Android include finding out the running apps and processes. Before you can execute commands, you must first set up ADB on your computer and enable USB debugging on your Android.
Listing All Background Apps and Processes
There is a simple yet powerful ADB command to list all background processes on a connected Android device. (PID means Process ID)
adb shell ps or adb shell ps -A
You can also use the following command to list all running activities on your Android device.
Checking CPU and Memory Usage for Apps
The top
command is used in Linux to get a real-time view of the running system processes. Being based on Linux, Android supports this command too.
Open the ‘platform-tools‘ folder that contains the ADB and Fastboot drivers. Type “powershell” in the folder’s address bar and hit Enter to launch a command window with its path.
Extend your phone’s screen timeout to 5-10 minutes temporarily and connect it to your computer using a USB cable. Now execute the following command.
adb shell
After the $ sign type ‘top‘ and press Enter.
You can also use the command as mentioned below.
adb shell top
It’s also possible to list the 5, 10, or any number of most CPU-hogging processes on your Android device.
adb shell top -m 10
If you want to sort top running processes by their memory and CPU consumption, use the following commands.
Sort by Memory usage: adb shell top -s 6
Sort by CPU usage: adb shell top -s 9
Like other ADB commands, this command can be used with certain variables to get more specific information.
-h
: Usage graphs instead of text-k
: Fallback sort FIELDS (default -S,-%CPU,-ETIME,-PID)-o
: Show Fields (def PID, User, PR, NI, VIRT, RES, SHR, S,%CPU, %MEM, TIME+, CMDLINE)-s
: Sort by field number (1-X, default 9)-b
: Batch mode (no tty)-d
: Delay Seconds between each cycle (default 3)-m
: Maximum number of tasks to show-n
: Exit after Number of iterations-p
: Show these PIDs-u
: Show these Users-q
: Quiet (no header lines)
Example: adb shell top -n 1
ADB can also help you check how much memory your apps are hogging.
adb shell dumpsys meminfo
Using the battery parameter with the dumpsys
command, you can check the battery’s health, capacity, and charge cycle count.
Getting Top Activity on Android and Kill It
ADB can also list the top foreground activity with its PID and kill the running process.
Execute the following command in the command window.
adb shell "dumpsys activity | grep top-activity"
This will give you the top activities with the Android app package name and PID. You can use its PID to kill the process.
"kill <PID>"
Alternatively, you can use the following ADB command to kill a process by its PID.
adb shell kill <PID>
To find the PID of a specific app by its package name, try the following.
adb shell pidof <package-name>
You can also check the currently running app with the command below.
adb shell dumpsys activity | awk -F '[ /}]' '/mCurrentFocus/{print $9}'
Get the List of the Most Recently Used Apps
You can easily check recently opened apps by tapping the App Switcher icon on the navigation bar. Alternatively, you can list the recent apps and their current activity with minute details using the following ADB commands.
adb shell dumpsys activity recents
The following command will give you a more compact output.
adb shell dumpsys activity top | grep "ACTIVITY"
To get the currently active foreground app or activity, you can use the above command as shown below.
adb shell dumpsys activity top | grep "ACTIVITY" | tail -n 1
Check If an App is Running and Stop It
ADB also has a command to find a running app or process and kill it via ADB to save battery on Android.
- Open a command prompt window on your computer and connect your device using a USB cable.
- Execute the following command to enter the Shell.
adb shell
- Now, type the command below to check if a specific app is active in the background.
ps -A | grep <package-name>
- If the app is active in the background, ADB will show the user ID, PID, and memory usage.
- You can kill or stop the app using the following commands.
-
am kill <package-name>
-
am force-stop <package-name>
-
- To verify if the background app was killed or stopped successfully, rerun the following command.
ps -A | grep <package-name>
- This time, you should get a blank output.
- That’s it.
There is another command that kills apps safely as the Android OS does when it needs resources. Since the command uses xargs
, it may not work on Windows
adb shell "ps | grep <package-name> | awk '{print $2}'" | xargs adb shell "run-as <package-name> kill"
Open Recents and Close Apps
When you use apps on your Android device, they are added to the Recents so you can switch between them quickly. Some of these apps may keep running in the background. You can view the recently used apps on Android by tapping the App Switcher button on the navigation bar and close them using the Close all or Clear all option.
Alternatively, you can simulate the same action directly from your computer through ADB commands.
- Connect your Android device to your computer, launch a command window, and issue the following command to open Recents.
adb shell input keyevent KEYCODE_APP_SWITCH
- When the Recents screen is open on your device, execute the following command twice one by one. Doing so will highlight the app in focus and then the Close all button.
adb shell input keyevent KEYCODE_DPAD_DOWN adb shell input keyevent KEYCODE_DPAD_DOWN
- Finally, enter the following command to select the highlighted item.
adb shell input keyevent KEYCODE_ENTER
- This will close or clear all apps from the Recents screen.
Check Background Apps via ADB
You’ll be surprised to see the sheer number of background activities and processes on an Android phone or tablet. To save yourself from getting overwhelmed, try the following command to list the apps running in the background on your Android device.
adb shell dumpsys activity activities adb shell dumpsys activity services
To fetch the list of current activities, try this:
adb shell dumpsys activity activities | grep mActivityComponent | cut -d= -f2 | sort -u -m
I tested the ADB commands to check the apps running in the background and foreground on the Samsung Galaxy S24 Ultra with One UI 6.1. Try them to see if they work on your device.