// Check to see if the service is currently running.
if (runningServiceInfoList.isEmpty()) { // The service is currently stopped.
- // Start the service.
- applicationContext.startService(Intent(applicationContext, RealtimeMonitoringService::class.java))
+ // Start the service as a foreground service, which is required because the worker is running in the background.
+ applicationContext.startForegroundService(Intent(applicationContext, RealtimeMonitoringService::class.java))
} else { // The service is currently running.
// Create a service connection.
val serviceConnection = object : ServiceConnection {