his application component operations is running in the background. This component does not provide a user interface. We can start the another services and it will continue to run in the background even if the user switches to another application. It even perform interprocess communication (IPC).
This service is used handle network transactions, play music, perform file I/O, or interact with a content provider, all running in the background.
started and bundle are two form of service.
- Started : The service start when We called the start service method by the activity. when another component calls startService() then services is start. Once service started, a service can run in the background indefinitely and must stop itself by calling stopSelf(), even if the component that started it is destroyed. For example, A good example, download or upload a file over the network. When the operation is done, the service should stop itself.
- Bound : This method is used to bound the service when an application component binds to it by calling bindService(). This service offers a client-server interface that allows components to interact with the service, send requests, get results, and even do so across processes with interprocess communication (IPC).The client can close the connection by calling unbindService(). Multiple clients can bind to the same service and when all of them unbind, the system destroys the service.
Life Cycle of Service
Life cycle of service is same as Activity life cycle. Service has many lifecycle callback methods. There are some life cycle method
- 1.startService() : This method is called when application service be started.This method return the ComponentName of the actual service.
- onCreate() : This method is called by the system when the service is first created. Do not call this method directly
- onStartCommand() : Thsi meyhod is called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it supplied and a unique integer token representing the start request.
- onBind() : This method is return the communication channel to the service. This method return null if clients can not bind to the service otherwise return IBinder
- onUnbind() : This method is called when all clients have disconnected from a particular interface published by the service.This method return boolean value. The default implementation does nothing and returns false.
- onRebind() : This method is called when new clients have connected to the service, after it had previously been notified that all had disconnected in its onUnbind(Intent).
- onDestroy() : This method is called by the system to notify a Service that it is no longer used and is being removed
public abstract ComponentName startService (Intent service)
public void onCreate ()
public int onStartCommand (Intent intent, int flags, int startId)
public abstract IBinder onBind (Intent intent)
public boolean onUnbind (Intent intent)
public void onRebind (Intent intent)
public void onDestroy ()