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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.