JulianAssmann / flutter_background

A flutter plugin to keep apps running in the background via foreground services. Android only.
https://pub.dev/packages/flutter_background
MIT License
86 stars 46 forks source link

[BUG] after running for some hours app restarts and the notification text changes to default. #9

Open chocovish opened 3 years ago

chocovish commented 3 years ago

This plugin works quite well except for the first time crash while granting permission. what I noticed that if I run the app for few hours like 8-9hours it restarts autoomatically (as I can see the "time since" thing in notification changes). and the notification title and description text switch backs to default (keeps the flutter app running in the background). attaching screenshot.

image

JulianAssmann commented 3 years ago

Thank you very much for the bug report! What device are you using? On my Pixel 5 I didn't observe this behavior yet, but maybe some OEMs kill long running apps after a while.

daurin-oshin commented 3 years ago

Good and excellent library. The same thing happened to me on a galaxy s9, the service only lasted 15 minutes, it only happened once for now, I don't know what the problem will be, maybe android kills the service, any other reason for this bug?

JulianAssmann commented 3 years ago

Interesting... Do you have any console logs available from when it resets/cancels the foreground service? I will try and investigate, but so far I haven't been able to reproduce the problem on my own device :(

akospwc commented 3 years ago

Excellent library, thank you for creating this, Julian!

For what it's worth, I am also experiencing this on a Samsung device. Might be unrelated, but Crashlytics also reported crashes at the same time. Let me know if you'd like me to create a separate issue for this instead (crash is coming from Samsung and Pixel devices, which covers 100% of the install base of our app)

Caused by java.lang.IllegalArgumentException: Parameter specified as non-null is null: method l.v.d.j.b, parameter intent
       at de.julianassmann.flutter_background.IsolateHolderService.onStartCommand(:2)
       at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4723)
       at android.app.ActivityThread.access$2000(ActivityThread.java:301)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2168)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:246)
       at android.app.ActivityThread.main(ActivityThread.java:8456)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
JulianAssmann commented 3 years ago

Thank you very much for the information, I will look into it when I have some time to spare :)

ViniciusDiasSilva commented 3 years ago

I have the same problem. Excellent library! Thanks!

JulianAssmann commented 3 years ago

Thank you for your kind words and the comment. Do you have the same stack trace as @akospwc or some other error?

akospwc commented 3 years ago

I believe what's happening here is that the app crashes and the OS automatically restarts the service. In this case initialize() is not getting called in time, meaning we are reverting to the default text.

I was able to reproduce this behavior with the example app:

The notification disappears and then reappears in a few seconds with the default text.

I fixed this by storing the notification's configuration in shared preferences and then reloading them before use. @JulianAssmann would you mind taking a look?

https://github.com/akospwc/flutter_background/commit/b942e4a88b9034260f62ac63d882017102a26841

luohao123 commented 1 year ago

Does hits merged?