Search code examples
androidadb

How to stop android service from a adb


am startservice com.xxx/.service.XXXService

i can start a service through the command above , but the am manual doesn't say anything about stop service.

how can i do that?


Solution

  • If you intend to stop a service you developed yourself you can add a second service to your app that is only responsible to stop the other service.

    Its onCreate() method only contains three lines of code:

    public void onCreate() {
      super.onCreate();
      stopService(new Intent("<ActionIDofServiceToBeStopped>"));
      stopSelf();
    }
    

    This way you can stop your service by just starting the second one via adb:

    am startservice '<IDofStopperService>'