Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
149 stars 109 forks source link

[android] foreground service stops when app is closed #243

Closed HasanAlqaisi closed 3 months ago

HasanAlqaisi commented 3 months ago

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?

TheValkDokk commented 3 months ago

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

HasanAlqaisi commented 3 months ago

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.

Dev-hwang commented 3 months ago

@HasanAlqaisi @TheValkDokk

The 7.4.3 version fixed the issue with code improvements :)

HasanAlqaisi commented 3 months ago

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