You can use the same method to simulate kill and restart the service.
Launched the service ( onStartCommand returns START_STICKY ), logcat shows:
08-13 11:55:38.649 24159-24159/? D/TAG: onCreate() 08-13 11:55:38.650 24159-24159/? D/TAG: onStartCommand: intent is null? false; flags=0; startId=1
At this point, the following command to kill the process:
adb shell ps | grep <package name> | awk '{print $2}' | xargs adb shell run-as <package name again> kill
The service was restarted immediately (note the new process identifier and the fact that the target is zero):
08-13 11:55:43.742 24236-24236/? D/TAG: onCreate() 08-13 11:55:43.743 24236-24236/? D/TAG: onStartCommand: intent is null? true; flags=0; startId=2
source share