Android ADB stop application command like force-stop for non rooted device
The first way
Requires root
Use kill
:
adb shell ps
=> Will list all running processes on the device and their process idsadb shell kill <PID>
=> Instead of <PID>
use process id of your application
The second way
In Eclipse open DDMS
perspective.
In Devices
view you will find all running processes.
Choose the process and click on Stop
.
![enter image description here][1]
The third way
It will kill only background process of an application.
adb shell am kill [options] <PACKAGE>
=> Kill all processes associated with (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience.
Options are:
--user <USER_ID> | all | current: Specify user whose processes to kill; all users if not specified.
The fourth way
Requires rootadb shell pm disable <PACKAGE>
=> Disable the given package or component (written as "package/class").
The fifth way
Note that run-as is only supported for apps that are signed with debug keys.run-as <package-name> kill <pid>
The sixth way
Introduced in Honeycombadb shell am force-stop <PACKAGE>
=> Force stop everything associated with (the app's package name).
P.S.: I know that the sixth method didn't work for you, but I think that it's important to add this method to the list, so everyone will know it.
[1]: http://i.stack.imgur.com/izRtJ.png
Stopping an Android app from console
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>
Is it possible to force stop an application I am debugging using adb in terminal?
You can close one by his pid using
adb shell kill <PID>
but I'm not sure of doing it with a package name.
How to kill native applications from 'adb shell'?
Chirag deleted it, so here it is again:
adb shell ps | grep com.myapp | awk '{print $2}' | xargs adb shell kill
This is to be run outside of the emulator. It is one long Unix command, not four commands with a visual separation. |
is syntax, interpreted by your (Ubuntu's) shell, which then pipes the output from adb, grep, etc., into the next. Only ps
is executed in the emulator.
Android terminate app from terminal
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.
Also, you can close forcefully by using pid
,
adb shell kill <PID>
Related Topics
How to Use and Style New Alertdialog from Appcompat 22.1 and Above
Differencebetween Fragment and Fragmentactivity
An Android App Remembers Its Data After Uninstall and Reinstall
Get the Distance Between Two Geo Points
How to Add Action Bar from Support Library into Preferenceactivity
Android Textview:"Do Not Concatenate Text Displayed with Settext"
Android Asynctask Testing with Android Test Framework
Wrong Requestcode in Onactivityresult
How to Open Standard Google Map Application from My Application
How to Programmatically Clear Application Data
Expand/Collapse Lollipop Toolbar Animation (Telegram App)
Autoincrement Versioncode with Gradle Extra Properties
Android Edittext Onchange Listener
How to Detect When the User Has Changed the Clock Time on Their Device