flutter_background_service
flutter_background_service copied to clipboard
Foreground service closes after hours of inactivity
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 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 Thanks for your response, unfortunately this doesnt seem to work on all vendor' devices
@Merikw Is it possible to tell about devices that you have tested? (brand, manufacturer, model, os version)
@bahman2000 it is happening at least on the Samsung S22 Ultra with android 13 and the OnePlus 9 with android 11
i have the same problem
I am having the same problem. anyone got the idea to resolve this?
@Merikw did you have any solution for this?
Facing same issue
@johnray016 no, unfortunately its still a problem
@bahman2000 any update about this?
Same issue
same issue , no idea ?
@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.