Stopping an Android app from console

2019-01-05 07:29发布

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 so much. Right now we uninstall/install the app each time to make sure the manual test cases start with a clean state.

10条回答
萌系小妹纸
2楼-- · 2019-01-05 08:03

If you have access to the application package, then you can install with the -r option and it will kill the process if it is currently running as a side effect. Like this:

adb -d install -r MyApp.apk ; adb -d shell am start -a android.intent.action.MAIN -n com.MyCompany.MyApp/.MyActivity

The -r option preserves the data currently associated with the app. However, if you want a clean slate like you mention you might not want to use that option.

查看更多
贪生不怕死
3楼-- · 2019-01-05 08:07

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...

查看更多
狗以群分
4楼-- · 2019-01-05 08:11

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.

查看更多
趁早两清
5楼-- · 2019-01-05 08:12
pkill NAMEofAPP

Non rooted marshmallow, termux & terminal emulator.

查看更多
登录 后发表回答