Foreground Service cannot be terminated

248 Views Asked by At

I am calling Foreground Service from the main activity by using startForegroundService(Intent(applicationContext, ForegroundService::class.java)) and when the activity is about to be destroyed, 'stopService(Intent(applicationContext, ForegroundService::class.java))' is called. onDestroy function in ForegroundService is implemented as follow:

override fun onDestroy() {
    super.onDestroy()
    stopForeground(STOP_FOREGROUND_REMOVE)
    stopSelf()
}

Although onDestroy function is called from Main activity, the process is not seemed to be terminated. (I am not seeing a message saying 'Process XXXXX terminated.' on the console of Android Studio). Is it not a proper way of terminating foreground service or missing some additional function calls?

0

There are 0 best solutions below