Android ADB stop application command like “force-stop” for non rooted device

后端 未结 4 1630
Happy的楠姐
Happy的楠姐 2020-11-27 10:52

I\'m trying to stop application on Android 2.3.7 device. But in this version of Android I can\'t use \"force-stop\" command. Do you know any other ways to close application

相关标签:
4条回答
  • 2020-11-27 11:23

    If you have a rooted device you can use kill command

    Connect to your device with adb:

    adb shell
    

    Once the session is established, you have to escalade privileges:

    su
    

    Then

    ps
    

    will list running processes. Note down the PID of the process you want to terminate. Then get rid of it

    kill PID
    
    0 讨论(0)
  • 2020-11-27 11:38

    If you want to kill the Sticky Service,the following command NOT WORKING:

    adb shell am force-stop <PACKAGE>
    adb shell kill <PID>
    

    The following command is WORKING:

    adb shell pm disable <PACKAGE>
    

    If you want to restart the app,you must run command below first:

    adb shell pm enable <PACKAGE>
    
    0 讨论(0)
  • 2020-11-27 11:39

    The first way
    Needs root

    Use kill:

    adb shell ps => Will list all running processes on the device and their process ids
    adb shell kill <PID> => Instead of <PID> use process id of your application

    The second way
    In Eclipse open DDMS perspective.
    In Devices view you will find all running processes.
    Choose the process and click on Stop.

    enter image description here

    The third way
    It will kill only background process of an application.

    adb shell am kill [options] <PACKAGE> => Kill all processes associated with (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:

    --user | all | current: Specify user whose processes to kill; all users if not specified.

    The fourth way
    Needs root

    adb shell pm disable <PACKAGE> => Disable the given package or component (written as "package/class").

    The fifth way
    Note that run-as is only supported for apps that are signed with debug keys.

    run-as <package-name> kill <pid>

    The sixth way
    Introduced in Honeycomb

    adb shell am force-stop <PACKAGE> => Force stop everything associated with (the app's package name).

    P.S.: I know that the sixth method didn't work for you, but I think that it's important to add this method to the list, so everyone will know it.

    0 讨论(0)
  • 2020-11-27 11:44

    To kill from the application, you can do:

    android.os.Process.killProcess(android.os.Process.myPid());
    
    0 讨论(0)
提交回复
热议问题