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

Stop the service

You can stop the service as,

$ adb shell am stop-service com.package.name/.YOUR_SERVICE_NAME
How to generate apk or aab in andro... x
How to generate apk or aab in android studio

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto Embedded Linux