Android service basics

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 ...

Get Mastering Android Development with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.