I need to call suspend function from onMessageRecieved(), but this service doesn't provide a scope. So I don't know from where to call job.cancel()
. How to use suspend function in this case?
FirebaseMessagingService
is a derived class of Service
, so you can use it's onDestroy()
to cancel your coroutines.
override fun onDestroy() {
super.onDestroy()
job.cancel()
}