

Or it can be unbound according to our requirement by using the unbindService() method. This service runs in the background as long as another application is bound to it. The components can send requests to services and get results. It gives a client-server relation that lets the components interact with the service. By stopping itself using the stopSelf() method.Ī service is bound only if an application component binds to it using bindService().This service can be stopped only in one of the two cases:

Once this service starts, it runs in the background even if the component that created it destroys. It performs a single operation and doesn’t return any result to the caller. Started ServiceĪ service becomes started only when an application component calls startService(). Let us see these services and their approach. Lifecycle of Android ServicesĪndroid services life-cycle can have two forms of services and they follow two paths, that are:

To bind an application component to the service, bindService() is used. Many components can bind to one service at a time, but once they all unbind, the service will destroy. Bound Servicesīound service runs as long as some other application componentis bound to it. Syncing and Storing data can be the best example. These are the tasks that don’t need the user to know them. These services run in the background, such that the user can’t see or access them. The perfect example of this is Music Player and Downloading. These services continue to run even when users are using other applications. The users can interact with them at ease and track what’s happening. Foreground Servicesįoreground services are those services that are visible to the users. The working of these three services is below: 1. When we talk about services, they can be of three types as shown in the figure below: They can be connected to other components and do inter-process communication (IPC).ĭid you check the previous tutorial on Android activity? Types of Android Services As they perform long-running processes without user intervention, they have no User Interface. We can understand it as a process that doesn’t need any direct user interaction. What are Android Services?Īndroid Services are the application components that run in the background. Now, let’s understand its technical part. Not sure how? Well, it runs in the background while the user happily uses some other application, isn’t it? For a better understanding, consider an online music player that uses the internet and plays music in the background. We offer you a brighter future with FREE online courses Start Now!!Įver thought of a music player, as a service? Yes, the music player is a service.
