flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

Foreground service closes after hours of inactivity

Open Merikw opened this issue 2 years ago • 12 comments

Hi,

For our current project we have implemented a foreground service which handles incoming notifications and shows it to the user. However, some user experience the foreground service being stopped. Most of the time this is after a long time of no use of the app (after a day of use and a night of no use of the phone at all). Any information about this? I found a website https://dontkillmyapp.com/ which lists the problems with background/foreground services for every vendor.

Furthermore, I read a lot about doze mode, run service as START_STICKY and a partial wake lock but this all seems to be already implemented in this package. Is there anything that I need to configure to make use of this which I might have forgotten?

Thanks!

Merikw avatar Jan 16 '23 13:01 Merikw

@Merikw Hi, Navigate user to battery optimization settings intent and let him/her to disable battery optimization for your app. This solution will probably work for your use case.

bahman2000 avatar Jan 17 '23 05:01 bahman2000

@bahman2000 Thanks for your response, unfortunately this doesnt seem to work on all vendor' devices

Merikw avatar Jan 17 '23 07:01 Merikw

@Merikw Is it possible to tell about devices that you have tested? (brand, manufacturer, model, os version)

bahman2000 avatar Jan 17 '23 08:01 bahman2000

@bahman2000 it is happening at least on the Samsung S22 Ultra with android 13 and the OnePlus 9 with android 11

Merikw avatar Jan 19 '23 12:01 Merikw

i have the same problem

endmr11 avatar Jan 27 '23 09:01 endmr11

I am having the same problem. anyone got the idea to resolve this?

@Merikw did you have any solution for this?

johnray016 avatar Feb 09 '23 01:02 johnray016

Facing same issue

kevinconcourse avatar Feb 28 '23 12:02 kevinconcourse

@johnray016 no, unfortunately its still a problem

Merikw avatar Mar 28 '23 08:03 Merikw

@bahman2000 any update about this?

Merikw avatar Mar 29 '23 07:03 Merikw

Same issue

mozomig avatar Apr 26 '23 19:04 mozomig

same issue , no idea ?

teddy-dubal avatar Aug 14 '23 22:08 teddy-dubal

@Merikw @johnray016 @endmr11 @kevinconcourse @mozomig @teddy-dubal

In recent Android versions, keeping the background service alive forever on all different phones (various android versions & phone manufacturers) is really a challenge. Each phone manufacturer changes pure android according to its own policies. The most important factor is battery consumption in the phone, which causes the service to be killed. My suggestion is that you use the background service only for a short period of time and stop it after completing the desired task. Now the question is how to start the background service when you have a new task and the app is terminated? For this purpose, FCM is a good option. Because you are sure that the client will receive the notification at the desired time (when the app is in the foreground or background or terminated) and you will start the background service to execute the task. Also, FCM messages are handled by a callback function and you can only use this function to execute your task and do not start the background service.

bahman2000 avatar Nov 06 '23 07:11 bahman2000