How can I kill all active tasks / applications using ADB?

Is it possible to kill ALL active tasks / applications in the task manager using ADB? This would be equivalent to opening a task manager and killing each task in turn ...

I tried using the following adb shell command , but that did not kill the whole task.

adb shell am kill-all

I cannot use the command adb shell am force-stop <PACKAGE>because I need to know which package / application is running. I want to kill ALL the tasks performed by user applications. Similar to using the task manager and killing each task one at a time.

According to the command description, kill-all kills all background processes. Are background processes equivalent to "services" and tasks of equivalent "activity"?

In addition, is it possible to clear application cache applications using ADB while storing user data? It seems to adb shell pm clearclear all user data. I only want to clear the cache.

The reason I ask is because I am testing several performance tests in multiple user applications. To make each test valid, I want none of the user's applications to perform any tasks, actions, services, and caching in the background.

+4
source share
4 answers

, ,

adb shell pm clear com.yourapp.package
+6

, .. , :

adb shell ps|grep -v root|grep -v system|grep -v NAME|grep -v shell|grep -v smartcard|grep -v androidshmservice|grep -v bluetooth|grep -v radio|grep -v nfc|grep -v "com.android."|grep -v "android.process."|grep -v "com.google.android."|grep -v "com.sec.android."|grep -v "com.google.process."|grep -v "com.samsung.android."|grep -v "com.smlds" |awk '{print $2}'| xargs adb shell kill

, ; grep -v "exception"

+1

force-stop, root.

adb shell am force-stop <PACKAGE>

/

adb shell "dumpsys activity | grep top-activity"

, , Java, :

public void parseResult(String line){
        int i = line.indexOf(" 0 ");
        if(i == -1){
            return;
        }
        line = line.substring(i);
        i = line.indexOf(":");
        if(i == -1){
            return;
        }
        line = line.substring(i + 1);
        i = line.indexOf("/");
        return line.substring(0, i);
}
+1

- Faisal Ameer Script

adb shell ps | grep -v root | grep -v system | grep -v "android.process." | grep -v radio | grep -v "com.google.process." | grep -v "com.lge." | grep -v shell | grep -v NAME | awk '{print $NF}' | tr '\r' ' ' | xargs adb shell am force-stop

adb shell am force-stopdoes not require root permission. Please note that applications are still displayed on devices running the application box, but I confirmed that the package processes were cleared with.

adb shell dumpsys meminfo relevant.package.names
0
source

All Articles