Stopping an Android app from console

前端 未结 11 629
情书的邮戳
情书的邮戳 2020-11-27 09:30

Is it possible to stop an Android app from the console? Something like:

adb stop com.my.app.package

It would speed up our testing process s

相关标签:
11条回答
  • 2020-11-27 09:36

    In eclipse go to the DDMS perspective and in the devices tab click the process you want to kill under the device you want to kill it on. You then just need to press the stop button and it should kill the process.

    I'm not sure how you'd do this from the command line tool but there must be a way. Maybe you do it through the adb shell...

    0 讨论(0)
  • 2020-11-27 09:37
    pkill NAMEofAPP
    

    Non rooted marshmallow, termux & terminal emulator.

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

    The clean way of stopping the app is:

    adb shell am force-stop com.my.app.package
    

    This way you don't have to figure out the process ID.

    0 讨论(0)
  • 2020-11-27 09:47

    First, put the app into the background (press the device's home button)

    Then....in a terminal....

    adb shell am kill com.your.package
    
    0 讨论(0)
  • 2020-11-27 09:51

    Edit: Long after I wrote this post and it was accepted as the answer, the am force-stop command was implemented by the Android team, as mentioned in this answer.

    Alternatively: Rather than just stopping the app, since you mention wanting a "clean slate" for each test run, you can use adb shell pm clear com.my.app.package, which will stop the app process and clear out all the stored data for that app.


    If you're on Linux:
    adb shell ps | grep com.myapp | awk '{print $2}' | xargs adb shell kill

    That will only work for devices/emulators where you have root immediately upon running a shell. That can probably be refined slightly to call su beforehand.

    Otherwise, you can do (manually, or I suppose scripted):
    pc $ adb -d shell
    android $ su
    android # ps
    android # kill <process id from ps output>

    0 讨论(0)
  • 2020-11-27 09:54

    adb shell killall -9 com.your.package.name

    according to MAC "mandatory access control" you probably have the permission to kill process which is not started by root

    have fun!

    0 讨论(0)
提交回复
热议问题