flutter_background_service icon indicating copy to clipboard operation
flutter_background_service copied to clipboard

Crashes Android 11 and below

Open markalroberts opened this issue 1 year ago • 6 comments

This package works fine on Android 12 and 13, but for Android 11 and below it crashes the app when it tries to restart the service on the background:

Here is the my log:

D/AndroidRuntime(11004): Shutting down VM
E/AndroidRuntime(11004): FATAL EXCEPTION: main
E/AndroidRuntime(11004): Process: com.company.app, PID: 11004
E/AndroidRuntime(11004): java.lang.RuntimeException: Unable to start receiver id.flutter.flutter_background_service.WatchdogReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.company.app/id.flutter.flutter_background_service.BackgroundService }: app is in background uid UidRecord{7492fe u0a154 RCVR bg:+1m5s21ms idle change:uncached procs:1 seq(0,0,0)}
E/AndroidRuntime(11004): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4041)
E/AndroidRuntime(11004): 	at android.app.ActivityThread.access$1400(ActivityThread.java:237)
E/AndroidRuntime(11004): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)
E/AndroidRuntime(11004): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(11004): 	at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime(11004): 	at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime(11004): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(11004): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime(11004): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime(11004): Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.company.app/id.flutter.flutter_background_service.BackgroundService }: app is in background uid UidRecord{7492fe u0a154 RCVR bg:+1m5s21ms idle change:uncached procs:1 seq(0,0,0)}
E/AndroidRuntime(11004): 	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1715)
E/AndroidRuntime(11004): 	at android.app.ContextImpl.startService(ContextImpl.java:1670)
2
E/AndroidRuntime(11004): 	at android.content.ContextWrapper.startService(ContextWrapper.java:720)
E/AndroidRuntime(11004): 	at id.flutter.flutter_background_service.WatchdogReceiver.onReceive(WatchdogReceiver.java:72)
E/AndroidRuntime(11004): 	at android.app.ActivityThread.handleReceiver(ActivityThread.java:4032)
E/AndroidRuntime(11004): 	... 8 more

markalroberts avatar Oct 01 '23 16:10 markalroberts

Same here!

1encore avatar Oct 19 '23 10:10 1encore

Same here

tinyCoder32 avatar Oct 19 '23 16:10 tinyCoder32

Same here

Abdullatif-Eida avatar Oct 19 '23 16:10 Abdullatif-Eida

I have raised a PR for this fix. Until owner will merge it you can use flutter_background_service: #MIT LICENSE git: url: https://github.com/ekasetiawans/flutter_background_service.git ref: 78dc190 path: packages/flutter_background_service flutter_background_service_android: git: url: https://github.com/ekasetiawans/flutter_background_service.git ref: 37200c0 path: packages/flutter_background_service_android

prkay avatar Nov 05 '23 14:11 prkay