ekasetiawans / flutter_background_service

264 stars 183 forks source link

Background Service Preparing #232

Open shajedulislam opened 1 year ago

shajedulislam commented 1 year ago

Our app was working fine. We released a new version of our app and after that this notification is showing. We didn't updated anything related to the background service. It's just some ui changes. The only difference is, new flutter version.

Problem in: Flutter version 3.3.2 flutter_background_service: 2.1.3

After updating flutter_background_service to 2.4.3 its working fine and notification title is ok but the old notification still remains even after phone restart. Is there any solution without uninstall?

Note: We stop service on app start/phone reboot based on requirement. Code is ok as it was working fine as well as now. Only problem is the notification Background Service Preparing still remains.

ekasetiawans commented 1 year ago

did you pass autoStartOnBoot argument in AndroidConfiguration?, I forgot to mention that was a breaking changes in the latest version.

shajedulislam commented 1 year ago

@ekasetiawans we passed autoStart like before not autoStartOnBoot. Ok, I will add it. We are facing another problem after the update.

Actually, we are using this service for a timer app with the location. As I told you it worked perfectly before mentioned update. Now another problem we are facing is, after stopping the background service the notification still remains on the notification bar. Trying start-stop the background 1-2 times then finally it disappears.

I checked with,

serviceInstance
          .stopSelf()
          .then((value) => print("===serviceInstance.stopSelf()==="));

on the first stop, it does not work but on 1-2 start and stops it works and prints above string.

It didn't happen before. Do you have any suggestions?

shajedulislam commented 1 year ago

@ekasetiawans Update!

I tested with more cases. It seems,

If I start the background service, close and reopen then try to stop the service, that time the notification still remains. I mean service doesn't stop. But if I start the service and stop it without closing even minimize, it stops.

So this happens only if I start service->close app->open app->stop service.

NOTE : It worked before update.

shajedulislam commented 1 year ago

Update!

Finally, I found the issue. Actually, when a user terminates the app background service stops. The notification still remains but background service stops on app termination.

ekasetiawans commented 1 year ago

@shajedulislam is it happened to in android emulator? Currently, my android device is broken so I can't make a test on real device.

shajedulislam commented 1 year ago

@ekasetiawans it happens with the emulator and real device both.

We have sentry to log errors or crashes. We found something. Hope it will be helpful for you.

Unable to destroy activity {com.flyhub.flyhubplay/com.flyhub.flyhubplay.MainActivity}: java.lang.IllegalArgumentException: Service not registered: id.flutter.flutter_background_service.a$a@a0f102e

We get this error when we try to stop background service by opening the app after termination. Also, check the below log. Hope these are also helpful.

java.lang.IllegalArgumentException: Service not registered: id.flutter.flutter_background_service.a$a@a0f102e at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:2039) at android.app.ContextImpl.unbindService(ContextImpl.java:2100) at android.content.ContextWrapper.unbindService(ContextWrapper.java:865) at id.flutter.flutter_background_service.a.onDetachedFromEngine(FlutterBackgroundServicePlugin.java:4) at io.flutter.embedding.engine.c.y(FlutterEngineConnectionRegistry.java:23) at io.flutter.embedding.engine.c.z(FlutterEngineConnectionRegistry.java:2) at io.flutter.embedding.engine.c.A(FlutterEngineConnectionRegistry.java:1) at io.flutter.embedding.engine.c.o(FlutterEngineConnectionRegistry.java:3) at io.flutter.embedding.engine.a.e(FlutterEngine.java:4) at io.flutter.embedding.android.e.t(FlutterActivityAndFragmentDelegate.java:15) at io.flutter.embedding.android.d.onDestroy(FlutterActivity.java:4) at android.app.Activity.performDestroy(Activity.java:8571) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1364) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5937) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5995) at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8669) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) java.lang.RuntimeException: Unable to destroy activity {com.flyhub.flyhubplay/com.flyhub.flyhubplay.MainActivity}: java.lang.IllegalArgumentException: Service not registered: id.flutter.flutter_background_service.a$a@a0f102e at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5950) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5995) at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8669) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

ekasetiawans commented 1 year ago

@ekasetiawans it happens with the emulator and real device both.

We have sentry to log errors or crashes. We found something. Hope it will be helpful for you.

Unable to destroy activity {com.flyhub.flyhubplay/com.flyhub.flyhubplay.MainActivity}: java.lang.IllegalArgumentException: Service not registered: id.flutter.flutter_background_service.a$a@a0f102e

We get this error when we try to stop background service by opening the app after termination. Also, check the below log. Hope these are also helpful.

java.lang.IllegalArgumentException: Service not registered: id.flutter.flutter_background_service.a$a@a0f102e at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:2039) at android.app.ContextImpl.unbindService(ContextImpl.java:2100) at android.content.ContextWrapper.unbindService(ContextWrapper.java:865) at id.flutter.flutter_background_service.a.onDetachedFromEngine(FlutterBackgroundServicePlugin.java:4) at io.flutter.embedding.engine.c.y(FlutterEngineConnectionRegistry.java:23) at io.flutter.embedding.engine.c.z(FlutterEngineConnectionRegistry.java:2) at io.flutter.embedding.engine.c.A(FlutterEngineConnectionRegistry.java:1) at io.flutter.embedding.engine.c.o(FlutterEngineConnectionRegistry.java:3) at io.flutter.embedding.engine.a.e(FlutterEngine.java:4) at io.flutter.embedding.android.e.t(FlutterActivityAndFragmentDelegate.java:15) at io.flutter.embedding.android.d.onDestroy(FlutterActivity.java:4) at android.app.Activity.performDestroy(Activity.java:8571) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1364) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5937) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5995) at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8669) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) java.lang.RuntimeException: Unable to destroy activity {com.flyhub.flyhubplay/com.flyhub.flyhubplay.MainActivity}: java.lang.IllegalArgumentException: Service not registered: id.flutter.flutter_background_service.a$a@a0f102e at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5950) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5995) at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8669) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

it's seems the BackgroundService.class is obfuscated by proguard, try to keep it in proguard config or disable obfuscation.

ekasetiawans commented 1 year ago

@shajedulislam I just added the default proguard config in flutter_background_service_android to keep everything in this plugin. Could you try to update the flutter_background_service plugin to the latest version in your pubspec.yaml?

shajedulislam commented 1 year ago

@ekasetiawans The problem still remains. After updating the package we are still getting the issue.

Without terminating the app background service can be stopped but if we terminate the app and try to stop after re-opening the app it does not work.

shajedulislam commented 1 year ago

in readme you mentioned to use gradle version 7.1.2 but we are using 7.0.4.

Is it causing the issue?

shajedulislam commented 1 year ago

I tried using mentioned Gradle still the same.

TheauLep commented 1 year ago

Hey @shajedulislam did u find the solution for the "App preparing" problem ?

shajedulislam commented 1 year ago

@TheauLep Nop.

TheauLep commented 1 year ago

@shajedulislam try looking to #246 I hope it can help you

shajedulislam commented 1 year ago

@TheauLep The issue is different. While the service is on, if you terminate the app, repoen and try to stop the service then it will not work. Because of termination service gets unregistered/detached.

GB945 commented 1 year ago

@shajedulislam did you able to resolve this issue. Facing same issue.