To define Android service, you have to extend the Service class. We must override some of the following methods so the service is functioning:
- onStartCommand(): This method is executed when the startService() method is triggered by some Android component. After the method is executed, Android service is started and can run in the background indefinitely. To stop this service, you must execute the stopService() method that has an opposite functionality to the startService() method.
- onBind(): To bind to the service from another Android component, use the bindService() method. After we bind, the onBind() method is executed. In your service implementation of this method, you must provide an interface that clients use to communicate with the service by returning an Ibinder class instance. Implementing this method is not optional, but if you don't plan to...