Stopping the service

To stop the service, execute the stopService() method from the Android Context class like this:

     val stopServiceIntent = Intent(ctx, MainService::class.java)     ctx.stopService(startServiceIntent) 

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.