Services

Services

Service life cycle

Service is one of the component of Android, runs in the background to perform long-running operations. It doesn't require user interaction.

It works even if the component(ex. activity) which started is destroyed or the app destroyed.

A started service must manage its own lifecycle.

You can start a service from an activity or other application component by passing an Intent to startService().

No alt text provided for this image

The Android system calls the service's onStartCommand() method and passes it the Intent, which specifies which service to start. The system doesn't stop or destroy the service unless it must recover system memory.

The service must stop itself by calling stopSelf(), or another component can stop it by calling stopService().

No alt text provided for this image

The service either can run in the thread where it has called or it runs in the same thread as the component which has started the service.

Running in main Thread
Runninng in different Thread


Android Jetpack using Work manager !

To view or add a comment, sign in

More articles by Apurba Gouda

Explore content categories