I know how to start an APK from the shell using this command:
adb shell am start -a android.intent.action.MAIN -n package name/activity name
Is there a way to quit the apk using shell commands? Thanks!
Try:
adb shell am kill com.blah.foo
From help docs: "am kill: Kill all processes associated with PACKAGE. Only kills processes that are safe to kill -- that is, will not impact the user experience."
In other words: If you are actively using the application this will not kill it. It will only kill an application that is ready to be killed.
So if you wish to kill an application that is actively running use:
adb shell am force-stop com.blah.foo
This will close it without regard to what it affects
I just used ps to find the PID of the process.
Then I used kill [pid] to kill that process.
This worked, but if there is any other way, help would be appreciated!
Related
I want to kill app process of my app for testing purpose. I want to test activity restoration.
I send my app to background by pressing home button. Then I run this command adb shell am kill <PACKAGE_NAME> in Android Studio terminal, but it doesn't kill app process.
Use force-stop instead
adb shell am force-stop package-name
I use the following command to start playing a movie on my android device:
adb shell am start -d file:///sdcard/fff.wvm -t video/3gp -a android.intent.action.VIEW
I want to stop (kill) the process before it finishes. Does anyone know the process name "am start" command create? I used ps to get the running processes in the background, but there is a lot, and it is hard to tell which one is.
If you know the package being started, use:
adb shell am force-stop <PACKAGE>
For me com.android.gallery worked pretty fine, however this depends on the installed app and preferred apps, of course. Going i.e. pushing Back might end the playback - it least it worked with the system player:
adb shell input keyevent 4
Appending the command ...
adb shell am kill-all
... should kill the process afterwards.
I'm trying to stop application on Android 2.3.7 device. But in this version of Android I can't use "force-stop" command. Do you know any other ways to close application on non rooted device?
The first way
Requires root
Use kill:
adb shell ps => Will list all running processes on the device and their process ids
adb 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.
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 root
adb 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 Honeycomb
adb 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.
If you have a rooted device you can use kill command
Connect to your device with adb:
adb shell
Once the session is established, you have to escalade privileges:
su
Then
ps
will list running processes. Note down the PID of the process you want to terminate. Then get rid of it
kill PID
If you want to kill the Sticky Service,the following command NOT WORKING:
adb shell am force-stop <PACKAGE>
adb shell kill <PID>
The following command is WORKING:
adb shell pm disable <PACKAGE>
If you want to restart the app,you must run command below first:
adb shell pm enable <PACKAGE>
To kill from the application, you can do:
android.os.Process.killProcess(android.os.Process.myPid());
I hope to stop all backgroud processes.
I got to know that adb shell am kill-all may do this job. I exit one application by pressing BACK,
then I enter adb shell am kill-all, However, I find the process by entering adb shell ps | grep packagename.
Does adb shell am kill-all really work?
If you don't have to kill background process with adb shell command. You can use some task manager in play store.
I also developed a task manager by myself, there are source codes:
https://code.google.com/p/my-test-project-lion/
I am able to start native applications using am start -a action -n packagename/activity. How can I kill/stop a native application from adb shell?
adb shell am force-stop packagename
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.
Another way to kill your app is to send your app to backround (using home button) and call:
adb shell am kill com.your.package
It works not on all of my devices, however, on devices where it works it behaves the same way as if the app was killed in background due to lack of resources and this state is often handy to test different aspects of your process recreation.
For example, if you have Broadcast Receivers registered in Manifest, they will still start without restarting your app manually, comparing to force stop that you can achieve using:
adb shell am force-stop com.your.package
Please try the below command in adb shell.
adb shell kill <PID>