开发者

Is it possible to "force stop" an application I am debugging using adb in terminal?

I am developing an app, and for debuggin开发者_JS百科g 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?


am force-stop YOUR.PACKAGE.NAME

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


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 }')


You can close one by his pid using

adb shell kill <PID>

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


adb killall YOUR.PACKAGE.NAME

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜