How to Start and Stop android service from adb shell

If you have followed our another article “Understanding Android Services with Example” you might be allready able to write a code to create android service and get it compiled. Once you install this service on to your android device using “adb install” command, you will need to start this service to execute the functionality written in service.

This article helps you to start the android service from adb shell,

Before Android Oreo ( Android-O ) or API level 26, you can start the service as,

$ adb shell am start-service com.package.name/.YOUR_SERVICE_NAME

For example, if your service package is “com.android.TestService” and service name is “HelloService” then you can start the service as,

$ adb shell am start-service com.android.TestService/.HelloService

After Android Oreo or API level 26 and more, you need to start the service as,

$ adb shell am start-foreground-service com.package.name/.YOUR_SERVICE_NAME

For example, if your service package is “com.android.TestService” and service name is “HelloService” then you can start the service as,

$ adb shell am start-foreground-service com.android.TestService/.HelloService

Stopping the service

You can stop the service as,

$ adb shell am stop-service com.package.name/.YOUR_SERVICE_NAME

Leave a Comment