Stopping an Android app from console


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

adb stop

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.

6/25/2010 10:00:40 AM

Accepted Answer

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

11/6/2017 4:13:29 PM

The clean way of stopping the app is:

adb shell am force-stop

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow