Dev-hwang/flutter_foreground_task

[android] foreground service stops when app is closed

Closed this issue · 4 comments

Hi,
I am using the package for android and it works great.
The only issue I have is that the service is stopping once the user closes the app (from the task manager).
It is also happening in the example app.
Is this use case not supported by the package? Or am I missing something?

i just got this happen on the recent 7.4.0, previously 7.2.0 it was working fine, i update it because i need the 2 way communication between the TaskHandler and Main Ui Thread, hope @Dev-hwang can fix it soon

Edit: previously on 7.2.0, kill the app in main ui thread will not effect the foreground in anyway, now it's will kill the foreground notification and the foreground will try to restart, sometime it shows the notification but sometime it's shows under foreground manager with no notification

i just got this happen on the recent 7.4.0, previously 7.2.0 it was working fine, i update it because i need the 2 way communication between the TaskHandler and Main Ui Thread, hope @Dev-hwang can fix it soon

Edit: previously on 7.2.0, kill the app in main ui thread will not effect the foreground in anyway, now it's will kill the foreground notification and the foreground will try to restart, sometime it shows the notification but sometime it's shows under foreground manager with no notification

From my side, on 7.2.0, if the app is closed it will try to restart the service but this needs the battery optimization to be turned off.
I don't want to rely on the user to turn off the battery optimization.

Also I found that if I comment the stopSelf() in the source code, the service will not be killed:

    override fun onTaskRemoved(rootIntent: Intent?) {
        super.onTaskRemoved(rootIntent)
        stopSelf()
    }

If this is the reason, then having a flag to let the package users decide would be great.

@HasanAlqaisi @TheValkDokk

The 7.4.3 version fixed the issue with code improvements :)

7.4.3 version indeed fixed the issue! Thanks for the quick fix.