Override function onTaskRemoved of service is not getting called in the Redmi Device

89 Views Asked by At

I have an use case like on user kills/clear the app manually, a function to be triggered ,I have tried using the onDestroy unfortunately the fn is not called hence I have gone with service and implement as below code

class MyService: Service() {
override fun onBind(intent: Intent?): IBinder? {
    return null
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    println("MyService - onStartCommand service")
    return START_STICKY
}

override fun onTaskRemoved(rootIntent: Intent?) {
    super.onTaskRemoved(rootIntent)
    println("MyService - onTaskRemoved service")
    viewModel.manageUserSessionLeave()
}

companion object {
    val isUserRemoved: MutableSharedFlow<Boolean> = MutableSharedFlow()
    internal lateinit var viewModel:GocxViewModel
}

}

In Activity :

val intent = Intent(applicationContext, MyService::class.java)
    startService(intent)

and by this code I am able to receive the "onTaskRemoved" in Samsung Device but in redmi device the fn is not triggered, Kindly help on how the use case can be met regardless of the OS

0

There are 0 best solutions below