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.
If all you are looking for is killing a package
pkill package_name
should work
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.
I tried all answers here on Linux nothing worked for debugging on unrooted device API Level 23, so i found an Alternative for debugging From Developer Options -> Apps section -> check Do Not keep activities that way when ever you put the app in background it gets killed
P.S remember to uncheck it after you finished debugging
First, put the app into the background (press the device's home button)
Then....in a terminal....
adb shell am kill com.your.package
pkill NAMEofAPP
Non rooted marshmallow, termux & terminal emulator.
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.
If you target a non-rooted device and/or have services in you APK that you don't want to stop as well, the other solutions won't work.
To solve this problem, I've resorted to a broadcast message receiver I've added to my activity in order to stop it.
public class TestActivity extends Activity {
private static final String STOP_COMMAND = "com.example.TestActivity.STOP";
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
TestActivity.this.finish();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//other stuff...
registerReceiver(broadcastReceiver, new IntentFilter(STOP_COMMAND));
}
}
That way, you can issue this adb command to stop your activity:
adb shell am broadcast -a com.example.TestActivity.STOP
you can use the following from the device console: pm disable com.my.app.package
which will kill it. Then use pm enable com.my.app.package
so that you can launch it again.
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...
adb shell killall -9 com.your.package.name
according to MAC "mandatory access control" you probably have the permission to kill process which is not started by root
have fun!
Source: Stackoverflow.com