flutter_foreground_task icon indicating copy to clipboard operation
flutter_foreground_task copied to clipboard

App getting killed in background

Open akshg05 opened this issue 2 years ago • 16 comments

I am using the Foreground task to keep my app alive when it's in the background. However, after some time which could be for 15 mins or 30 mins or an hour as well being uncertain, the app is killed along the foreground service. I do not do anything substantial in the foreground task other than what's in the example. I am using it to only keep the app alive in background. I am using Android 11 real device and have not called for batteryOptmization. Any guidance on this?

akshg05 avatar May 12 '22 10:05 akshg05

I'm getting reports, after client goes to sleep and wakes up, task notification disappears. Even when ignoring battery optimizations.

SomeoneIsWorking avatar Aug 17 '22 13:08 SomeoneIsWorking

Some device manufacturers like Samsung, one plus,oppo, vivo and xiaomi have their own battery savers which kill the app and all of it's services no matter what. You have to explicitly disable them on your app settings and sadly there is no other way out.

h2210316651 avatar Aug 22 '22 14:08 h2210316651

@h2210316651 I'm thinking of setting up a periodic firebase messaging that will try to restart the service it has stopped working. Do you think it will help?

SomeoneIsWorking avatar Aug 22 '22 14:08 SomeoneIsWorking

@h2210316651 I'm thinking of setting up a periodic firebase messaging that will try to restart the service it has stopped working. Do you think it will help?

Can you elaborate. firebase messaging as in Firebase Cloud Messaging?

h2210316651 avatar Aug 22 '22 14:08 h2210316651

@h2210316651 Yes FCM. When the app receives an FCM push notification, its handler will check if the service is running and run it if it isn't.

SomeoneIsWorking avatar Aug 22 '22 14:08 SomeoneIsWorking

@SomeoneIsWorking Sounds like a plan. I think it'll work Provided it has access to the flutterforgroundtask singleton. Let me know if it works.

h2210316651 avatar Aug 22 '22 14:08 h2210316651

@SomeoneIsWorking @h2210316651 @akshg05 @Dev-hwang - Any solution found for this?

hardikamal avatar Jan 05 '23 06:01 hardikamal

Any solution found for this?

@hardikamal We moved to using Firebase Cloud Messaging as the trigger mechanism for the recurring task

SomeoneIsWorking avatar Jan 20 '23 18:01 SomeoneIsWorking

Service is Getting Closed After Some Time Notification is disappearing . even after disabled battery optimization . any solution for this ?

RohitSadioura avatar Apr 03 '23 10:04 RohitSadioura

I have same problem. @RohitSadioura Did you find any solution?

aBuder avatar Jun 06 '23 14:06 aBuder

No @aBuder

RohitSadioura avatar Jun 07 '23 03:06 RohitSadioura

@aBuder

It would be helpful if you could tell me what caused the service to kill. This may be a memory problem or the service may be terminated according to the policy of a specific manufacturer and device. Using a service like the Firebase Crashlytics API may be able to identify the problem.

Dev-hwang avatar Jun 07 '23 05:06 Dev-hwang

@aBuder

If you're not communicating with dart main isolate, the settings below may help.

<service
        android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
        android:process=":remote" />

However, this separation of processes has the disadvantage of not being able to control the service.

Dev-hwang avatar Jun 07 '23 06:06 Dev-hwang

@aBuder @RohitSadioura

Also try the options below:

<application
        android:label="flutter_foreground_task_example"
        android:icon="@mipmap/ic_launcher"
        android:persistent="true"> <!-- this -->

</application>
image

Dev-hwang avatar Jun 07 '23 07:06 Dev-hwang

No App will still closed

aBuder avatar Feb 07 '24 21:02 aBuder

The problem I am trying to tackle now is app stops working in the background after some time but retains the sticky foreground notification. Our app counts steps so we make it in a way that it does that in the background and shows how many steps are counted in the sticky foreground notification. But many reports say the counter stops working and hangs at "x counted steps". I think this happens when the operating system tries to free resources by restarting the foreground service.

erisanolasheni avatar May 23 '24 06:05 erisanolasheni