3
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?

WoooHaaaa
  • 19,732
  • 32
  • 90
  • 138

2 Answers2

4
adb shell
ps | grep -i com.example.service
run-as com.example.service
kill -9 pId
exit

if your service work in the same process as your app. tested on android 5.1

lman
  • 133
  • 3
  • 7
0

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>'
Claas Wilke
  • 1,951
  • 1
  • 18
  • 29