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 s
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
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
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.
If all you are looking for is killing a package
pkill package_name
should work