What is Service in Android – Types of Service – Activities have a very short lifetime and can be shut-down at any time or can be closed as per need.
Whereas services are background programs that run continuously in the background without the knowledge of the user.
We can also call Services as Background Processes and consider the following diagrams as Background Processes which appear in the Task Manager of Windows OS, which have no User Interface, rather they are running Invisibly in the Background and different types The system and application related requirements are fulfilled:
For example when we are listening to a music on our Android Device, at the same time, we are also answering someone on our WhatsApp Application or are also doing multitasking while chatting with someone on Hangone App or Facebook App, But our music, while using WhatsApp, Facebook or Hangout App, is still running continuously, because it is running like a service in the background without our knowledge.
The only feature of the services is that they do not have to be a User Interface and even without the User Interface, they are fulfilling any of our requirement by running Invisibly in the background.
Services are one such way of Android OS, through which we can keep an operation running invisibly in the background. So when we have to keep a task running for a long time, such as uploading / downloading a large file, we create a service to meet this type of need.
Since there is no need to have a User Interface for Services, Stat Related Information related to Start, Activate, Pause, Resume or End etc. of the Services is handled through Notifications.
There are always two ways to create services:
Under the first method, a service is created through activity. Such services end with the stop of the activity through which they are created.
While under other methods these Activities are created independently, due to which they do not bounce with any activity of an application, as a result start or stop of an application has no effect on their run and Once started, they continue to run invisibly in the background.
If we say the same thing in another way, an Android system can define two types of services as Local Service and Remote Service. The service that is created as a Local Service can use only those applications of the Current Device that have created the service, whereas the service that has been created as a Remote Service can be used for that device. Various applications can be used as per your need.
Therefore, we can call Local Service as a service created by an activity through an application, whereas Remote Service can be called as an independently created Service.
We can also schedule the services to be executed repeatedly for the completion of a specific task at a given time and we can setup Cron-Jobs to do these scheduling, which we will know in detail.
Types of Service in Android
- Foreground Service
Closer view services are recognizable to the client and can perceive what’s going on or associate with the segment. For instance a Music player and Downloading document applications works. Forefront services keep running even clients are not collaborating or utilizing it.
- Background Service
Foundation service run out of sight without client knows or client can’t see it. For a model Storing information and Sync information to the worker. A few undertakings don’t have to show clients what is happing out of sight fo application.
- Bound service
Bound service runs just as long as another application part bound to it. Different segments can tie to the service without a moment’s delay, however in the event that every one of them unbind, the service will wreck. By calling,bindService() service is tie with the application segment.