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 thestartService()
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 thestopService()
method that has an opposite functionality to thestartService()
method.onBind()
: To bind to the service from another Android component, use thebindService()
method. After we bind, theonBind()
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 anIbinder
class instance. Implementing this method is not optional, but if you don't plan to bind to the service, just returnnull
.onCreate()
: This method is executed when the service is created. It is not executed...