Is it possible to “force stop” an application I am

2019-03-21 03:41发布

I am developing an app, and for debugging certain actions on first installation I found that using the terminal command:

./adb uninstall <package-name>

was a lot fast than navigating to settings, apps, waiting for the apps to load, finding your app, and uninstalling it. I would strongly recommend it for anyone that doesn't already use it for debugging.

Now I am trying to work on the force close part of my app, and I can't find anywhere in the android doc, instructions on how to force close an app by adb command.

Is it possible?

5条回答
Bombasti
2楼-- · 2019-03-21 03:46
adb killall YOUR.PACKAGE.NAME

I've created a batch script to run this command.

查看更多
做个烂人
3楼-- · 2019-03-21 03:47

You can use adb shell kill to kill the process, but first you need to find the process id. To do this you can use adb shell ps and parse the output. Here is a sample (assuming your development PC is Unix):

adb shell kill $(adb shell ps | grep YOUR.PACKAGE.NAME | awk '{ print $2 }')
查看更多
贼婆χ
4楼-- · 2019-03-21 03:52
am force-stop YOUR.PACKAGE.NAME

This command worked for me. Hope so this will help you as well.

查看更多
冷血范
5楼-- · 2019-03-21 04:01

If you can't use awk for some reason (incomplete cygwin installation in my case), the following might work:

adb shell ps | grep YOUR.PACKAGE.NAME | sed 's/\s\s*/ /g' | cut -d ' ' -f 2 | adb shell kill

Explanation: First, ps lists running processes. From the output, grep gets the line containing YOUR.PACKAGE.NAME. sed truncates consecutive spaces into one to help cut can get the package name part of that line. Finally, the process id is piped to kill.

查看更多
6楼-- · 2019-03-21 04:13

You can close one by his pid using

adb shell kill <PID>

but I'm not sure of doing it with a package name.

查看更多
登录 后发表回答