Search code examples
androidandroid-serviceandroid-lifecycleandroid-service-binding

What happens when i call stopSelf in onDestroy method?


I have such a method implementation and I want to understand what will happen when this method is called. Could you give me a hint

override fun onDestroy() {
        Timber.d("$this: onDestroy")
        stopSelf()
        super.onDestroy()
    }

Solution

  • onDestroy() should only be called by Android when the Service has already stopped. Android won't call onDestroy() if the Service is running. If you call stopSelf() in onDestroy() it should just do nothing, as the Service is already stopped.