Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leak on terminated app #986

Closed
1 task done
bujdy opened this issue Feb 19, 2022 · 79 comments
Closed
1 task done

Leak on terminated app #986

bujdy opened this issue Feb 19, 2022 · 79 comments
Labels
platform: android Issue is related to the Android platform. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels

Comments

@bujdy
Copy link

bujdy commented Feb 19, 2022

🐛 Bug Report

I wanted to try to listen to locations even after i terminate app so i added

            notificationText:
            "Example app will continue to receive your location even when you aren't using it",
            notificationTitle: "Running in Background",
            enableWakeLock: true,
          )

to settings. But when i terminate the app i get this leak

E/ActivityThread(13871): Activity com.enviroapp.enviroapp.MainActivity has leaked ServiceConnection com.baseflow.geolocator.GeolocatorPlugin$1@576aec9 that was originally bound here
E/ActivityThread(13871): android.app.ServiceConnectionLeaked: Activity com.enviroapp.enviroapp.MainActivity has leaked ServiceConnection com.baseflow.geolocator.GeolocatorPlugin$1@576aec9 that was originally bound here
E/ActivityThread(13871): 	at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1811)
E/ActivityThread(13871): 	at android.app.LoadedApk.getServiceDispatcherCommon(LoadedApk.java:1683)
E/ActivityThread(13871): 	at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1662)
E/ActivityThread(13871): 	at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1819)
E/ActivityThread(13871): 	at android.app.ContextImpl.bindService(ContextImpl.java:1749)
E/ActivityThread(13871): 	at android.content.ContextWrapper.bindService(ContextWrapper.java:756)
E/ActivityThread(13871): 	at com.baseflow.geolocator.GeolocatorPlugin.onAttachedToActivity(GeolocatorPlugin.java:126)
E/ActivityThread(13871): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.add(FlutterEngineConnectionRegistry.java:155)
E/ActivityThread(13871): 	at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:29)
E/ActivityThread(13871): 	at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread(13871): 	at io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister.registerGeneratedPlugins(GeneratedPluginRegister.java:80)
E/ActivityThread(13871): 	at io.flutter.embedding.android.FlutterActivity.configureFlutterEngine(FlutterActivity.java:1004)
E/ActivityThread(13871): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:191)
E/ActivityThread(13871): 	at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:459)
E/ActivityThread(13871): 	at android.app.Activity.performCreate(Activity.java:8000)
E/ActivityThread(13871): 	at android.app.Activity.performCreate(Activity.java:7984)
E/ActivityThread(13871): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
E/ActivityThread(13871): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
E/ActivityThread(13871): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
E/ActivityThread(13871): 	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
E/ActivityThread(13871): 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/ActivityThread(13871): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/ActivityThread(13871): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
E/ActivityThread(13871): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/ActivityThread(13871): 	at android.os.Looper.loop(Looper.java:223)
E/ActivityThread(13871): 	at android.app.ActivityThread.main(ActivityThread.java:7656)
E/ActivityThread(13871): 	at java.lang.reflect.Method.invoke(Native Method)
E/ActivityThread(13871): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/ActivityThread(13871): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
D/FlutterGeolocator(13871): Binding to location service.
D/FlutterGeolocator(13871): Destroying location service.
D/FlutterGeolocator(13871): Stop service in foreground.

Expected behavior

Wanted to fetch data in terminated state

Reproduction steps

I didnt find anything in issues..

Configuration

Same as in example
Version: ^8.2.0

Platform:

  • 🤖 Android
@Ksardias
Copy link

Ksardias commented Feb 19, 2022

I add
assert pluginBinding != null; pluginBinding .getActivity() .unbindService( serviceConnection );
to function onDetachedFromActivity in file GeolocatorPlugin.java

and it look like this

@Override
    public void onDetachedFromActivity() {
        assert pluginBinding != null;
        pluginBinding
              .getActivity()
              .unbindService(
                      serviceConnection
              );
        dispose();
        deregisterListeners();
    }
    

but I'am not sure, that this is correct for rest of functionality

@bujdy
Copy link
Author

bujdy commented Feb 23, 2022

This doesnt work for me i still get leaks

@bujdy
Copy link
Author

bujdy commented Feb 23, 2022

Now i get this message also
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter.baseflow.com/geolocator_updates. Response ID: 11

@TommasoAzz
Copy link

Same error, but to me it happens on app startup.
geolocator version ^8.2.0, minSdkVersion 29, targetSdkVersion 31, compileSdkVersion 31.
It works fine with Android 10, Android 11 (hence, not returning any error), not working in Android 12.

@bujdy bujdy mentioned this issue Mar 2, 2022
1 task
@mvanbeusekom mvanbeusekom added platform: android Issue is related to the Android platform. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels labels Mar 2, 2022
@Wackymax
Copy link
Contributor

Wackymax commented Mar 2, 2022

@mvanbeusekom I will have a look at it

@Wackymax
Copy link
Contributor

Wackymax commented Mar 2, 2022

Having a look at the code it seems like even though the service is starting in the foreground it is still dependent on the activity and the flutter engine associated with that activity so the service is not truly as detached as it should be. Terminating the activity this leads to the service having to be terminated with it, which is what is happening currently.

For the most part this will allow some form of background location with the system keeping the activity and the service alive on a best effort basis. This issues will mostly present itself if you have Do Not Keep Activities enabled on Android. I will have a look to see if I can implement this to be truly background enabled even when the activities are detached from the flutter engine but this may require a large amount of work on the library and potentially introduce breaking changes.

@bujdy
Copy link
Author

bujdy commented Mar 2, 2022

@Wackymax I understand its a lot of work. I dont need that feature right now. Problem is, when i terminate application (and i have enabled ForegroundNotificationConfig) it actually wont terminate the app? Android studio is showing that application is still running and i get these messages in console every millisecond. Can i somehow detach service when i terminate app? This is not happening if ForegroundNotificationConfig is not active.
image

@Wackymax
Copy link
Contributor

Wackymax commented Mar 2, 2022 via email

@bujdy
Copy link
Author

bujdy commented Mar 3, 2022

Any updates? Also i would like to ask, whats the meaning of "running in background"? Is it when app is only minimized or phone is sleeping, or when i kill/terminate app?

@Wackymax
Copy link
Contributor

Wackymax commented Mar 3, 2022 via email

@Wackymax
Copy link
Contributor

Wackymax commented Mar 8, 2022

PR to unbind the service is up

@bujdy
Copy link
Author

bujdy commented Mar 8, 2022

So i tried it with your fixed version. After killing app, android studio shows that app is still running.
image
Logs after i killed app:
image

@bujdy
Copy link
Author

bujdy commented Mar 8, 2022

@Wackymax is it only happening to me?

@Wackymax
Copy link
Contributor

Wackymax commented Mar 8, 2022

Hi Bujdy,

The PR was to address the leak reported by this issue. I am not sure why Android studio would still show the app as running but I think that is a different issue that will have to be investigated. I am also not sure if this is something that will be impacting production apps and if it is just the development environment that is impacted by this but we will have to investigate that.

@bujdy
Copy link
Author

bujdy commented Mar 8, 2022

Problem is that not only it shows application is still running, i still get leaks. For example i got another package where i listen to accelerometer. Because app is still running i get these leaks every millisecond
image

Even though i cancel all listeners. So there must be something wrong with killing the app when i got enabled ForegroundNotificationConfig

@mvanbeusekom
Copy link
Member

@bujdy To me it looks like in this case it is the accelerometer plugin that is still active.

According to the log it is trying to communicate on the method channel that no longer exists. The method channel mentioned is not used by the geolocator plugin.

Try removing the accelerometer plugin to see if the problem persists. If not you know it is the accelerometer plugin causing the current issues.

If the problem remains, it would be very helpful if you could create a small reproduction example app showing the same behavior. If you can provide such an example I can put some effort into debugging it tomorrow morning.

@Wackymax
Copy link
Contributor

Wackymax commented Mar 8, 2022

You are right, I can see the issue does still happen on my side. I am not sure why I didn't get it testing earlier. I am having a look on my side to see if I can identify possible solutions.

@Wackymax
Copy link
Contributor

Wackymax commented Mar 8, 2022

Ok so I had a look now and this is specifically related to the LocationServiceStatusReceiver and not the foreground service. Which is probably why I didn't pick up the issue earlier in my testing. I will make a PR to solve that issue for us. I had a look now at an older version of the library and I see the same behaviour where the app does not terminate when being killed and I am wondering if that is not perhaps a flutter issue, but it does seem to be related to streams communicating with native platforms.

@mvanbeusekom
Copy link
Member

@Wackymax Could be the same issue this PR is trying to solve: #971

I haven't merged this one because I had some remarks but the original author doesn't seem to be keen on solving them.

@Wackymax
Copy link
Contributor

Wackymax commented Mar 8, 2022

@mvanbeusekom you are correct it is the same logic. I have added in additional check on my side to ensure the foreground service is indeed stopped in a similar scenario where we are stopping the stream. Happy if we close that PR and proceed with mine?

@mvanbeusekom
Copy link
Member

Yes very happy!

@mvanbeusekom
Copy link
Member

I have just released version 3.1.2 of the geolocator_android package. This contains the fix provided by @Wackymax and should resolve this issue. @bujdy could you have another try (make sure to run flutter pub upgrade to update to the latest version)?

@bujdy
Copy link
Author

bujdy commented Mar 8, 2022

Good job guys, everything is working, app is being killed. Only one problem, i get this error when i kill app.

D/AndroidRuntime( 7373): Shutting down VM
E/AndroidRuntime( 7373): FATAL EXCEPTION: main
E/AndroidRuntime( 7373): Process: sk.bluelemons.enviroapp, PID: 7373
E/AndroidRuntime( 7373): java.lang.RuntimeException: Unable to destroy activity {sk.bluelemons.enviroapp/sk.bluelemons.enviroapp.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: null
E/AndroidRuntime( 7373): 	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5111)
E/AndroidRuntime( 7373): 	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5140)
E/AndroidRuntime( 7373): 	at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44)
E/AndroidRuntime( 7373): 	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
E/AndroidRuntime( 7373): 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
E/AndroidRuntime( 7373): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
E/AndroidRuntime( 7373): 	at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 7373): 	at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime( 7373): 	at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime( 7373): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7373): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime( 7373): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime( 7373): Caused by: java.lang.IllegalArgumentException: Receiver not registered: null
E/AndroidRuntime( 7373): 	at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:1435)
E/AndroidRuntime( 7373): 	at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1642)
E/AndroidRuntime( 7373): 	at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:715)
E/AndroidRuntime( 7373): 	at com.baseflow.geolocator.LocationServiceHandlerImpl.disposeListeners(LocationServiceHandlerImpl.java:70)
E/AndroidRuntime( 7373): 	at com.baseflow.geolocator.LocationServiceHandlerImpl.stopListening(LocationServiceHandlerImpl.java:41)
E/AndroidRuntime( 7373): 	at com.baseflow.geolocator.GeolocatorPlugin.onDetachedFromEngine(GeolocatorPlugin.java:108)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:273)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:283)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:291)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:121)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:425)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:669)
E/AndroidRuntime( 7373): 	at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:676)
E/AndroidRuntime( 7373): 	at android.app.Activity.performDestroy(Activity.java:8245)
E/AndroidRuntime( 7373): 	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1344)
E/AndroidRuntime( 7373): 	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5096)
E/AndroidRuntime( 7373): 	... 11 more

@mvanbeusekom
Copy link
Member

Seems like it is trying to unregister a receiver that is already null. Maybe we should add another null check just to be sure, what do you think @Wackymax ?

@mvanbeusekom
Copy link
Member

That explains the difference in the logs, thanks for confirming. No need to remove it and test again that shouldn't make a difference.

@bujdy
Copy link
Author

bujdy commented Mar 14, 2022

So other plugins got same problem?

@mvanbeusekom
Copy link
Member

@bujdy I haven't found the problem yet. The problem is that while I can reproduce the problem, @Wackymax is not able to do so. Since I don't have any experience with foreground services I also cannot tell if this is expected behaviour or really a bug. Android's documentation is also not really clear about it unfortunately.

With my limited knowledge the code seems correct and I can confirm that the right methods (unbind and stopSelf) are being called in the correct order.

@Wackymax
Copy link
Contributor

Based on my research the "Do Not Keep Activities" option is not guaranteed to kill the application and it can only kill the activity but keep the application proses alive. This decision is entirely up the the Android system however and is non-deterministic which may explain why it is difficult to reproduce. https://medium.com/inloopx/android-process-kill-and-the-big-implications-for-your-app-1ecbed4921cb

@bujdy
Copy link
Author

bujdy commented Mar 15, 2022

So there isn´t way to fix this and kill app? Or are you still investigating this issue?

@bujdy
Copy link
Author

bujdy commented Mar 18, 2022

Any news? @Wackymax @mvanbeusekom

@royer
Copy link

royer commented Mar 19, 2022

my project also has this problem, I just start my app and then terminate immediately. so nothing Geolocator method called. there have some leaked information in debug console.

D[/FlutterGeolocator]()( 5205): Creating service.
D[/FlutterGeolocator]()( 5205): Binding to location service.
E[/ActivityThread]()( 5205): Activity com.example.hunteraide.MainActivity has leaked ServiceConnection com.baseflow.geolocator.GeolocatorPlugin$1@7f87ea8 that was originally bound here
E[/ActivityThread]()( 5205): android.app.ServiceConnectionLeaked: Activity com.example.hunteraide.MainActivity has leaked ServiceConnection com.baseflow.geolocator.GeolocatorPlugin$1@7f87ea8 that was originally bound here
E[/ActivityThread]()( 5205): 	at com.baseflow.geolocator.GeolocatorPlugin.onAttachedToActivity(GeolocatorPlugin.java:126)
D[/FlutterGeolocator]()( 5205): Binding to location service.
D[/FlutterGeolocator]()( 5205): Destroying location service.
D[/FlutterGeolocator]()( 5205): Stop service in foreground.
D[/FlutterGeolocator]()( 5399): Creating service.
2
D[/FlutterGeolocator]()( 5399): Binding to location service.
D[/FlutterGeolocator]()( 5399): Destroying location service.
D[/FlutterGeolocator]()( 5399): Stopping location service.

and then I build a very fresh flutter project, do listening location even use foregroundNotificationConfig in this new project, everything is ok. no leaked information output.

I also make sure the compileSdkVersion and targetSdkVersion is same in both project.

I hope these information is useful.

@royer
Copy link

royer commented Mar 19, 2022

I found my problem. I checked pubspec.lock , find geolocator_android is 3.1.0, and the new fresh project is 3.1.3. I delete the geolocator in pubspec.yaml, and add it back, then geolocator_android is 3.1.3. the leaked information is gone.

@bujdy
Copy link
Author

bujdy commented Mar 22, 2022

But it still wont kill the application when you are trying to close it.

@bujdy
Copy link
Author

bujdy commented Mar 24, 2022

@Wackymax @mvanbeusekom is there anything you tried in past days?

@Wackymax
Copy link
Contributor

Wackymax commented Mar 24, 2022 via email

@mvanbeusekom
Copy link
Member

It is on my list but haven't had the time yet. Might be a couple of weeks. So if anyone wants to give it a go please feel free.

@bujdy
Copy link
Author

bujdy commented May 3, 2022

Any news on this?

@mvanbeusekom
Copy link
Member

I have tried with the latest updates in the Android package and no longer experience any issues anymore.

@Wackymax
Copy link
Contributor

Wackymax commented Oct 11, 2022 via email

@bazrafkan
Copy link

bazrafkan commented Oct 14, 2022

I have same problem with last version of geolocator_android (4.1.3) and geolocator(9.0.2), Devices: Pixel 2 and Pixel 5, I think this issue have same resone with this issue #1142.

@Wackymax Do you have any news? Thanks

E/FlutterGeolocator(24168): Geolocator position updates stopped
E/FlutterGeolocator(24168): There is still another flutter engine connected, not stopping location service

@Wackymax
Copy link
Contributor

I have same problem with last version of geolocator_android (4.1.3) and geolocator(9.0.2), Devices: Pixel 2 and Pixel 5, I think this issue have same resone with this issue #1142.

@Wackymax Do you have any news? Thanks

E/FlutterGeolocator(24168): Geolocator position updates stopped E/FlutterGeolocator(24168): There is still another flutter engine connected, not stopping location service

I am not entirely sure what you are asking? What you are seeing in the log messages is that you have multiple Flutter engines using the location service so it's not going to shut down otherwise the other Flutter engine won't receive location events.

I am also not seeing nor am I able to reproduce the issues reported by @bujdy

@Hhanri
Copy link

Hhanri commented Jun 15, 2023

I'm still facing this issue when I swipe the app (geolocator 9.0.2 with geolocator_android 4.1.9).
Also the notification and the location icon in status bar doesn't go away unless I force stop the app.

D/FlutterGeolocator(20710): Detaching Geolocator from activity
D/FlutterGeolocator(20710): Flutter engine disconnected. Connected engine count 1
D/FlutterGeolocator(20710): Disposing Geolocator services
E/FlutterGeolocator(20710): Geolocator position updates stopped
E/FlutterGeolocator(20710): There is still another flutter engine connected, not stopping location service
E/libEGL  (20710): call to OpenGL ES API with no current context (logged once per thread)
W/FlutterJNI(20710): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: flutter.baseflow.com/geolocator_updates_android. Response ID: 18

@mvanbeusekom
Copy link
Member

@Hhanri did you configure a timeout on the future returned?

If so you should have received a TimeoutException and this should also cancel/ stop listening for position updates.

@Hhanri
Copy link

Hhanri commented Jun 15, 2023

@mvanbeusekom I just tried that but it doesn't seem to stop the service when the app is already killed (swiped), notification and location icon are still showing up in the status bar and there is no TimeoutException in the console.
I tried background_locator_2 and location plugins, they both stop the service when the app is killed so I'm wondering why geolocator doesn't.

@Wackymax
Copy link
Contributor

Wackymax commented Jun 15, 2023 via email

@Hhanri
Copy link

Hhanri commented Jun 15, 2023

EDIT: I just tested geolocator on an empty project and the service stops properly, seems like the issue comes from me, sorry for bothering

Here are all the dependencies I'm using

  google_sign_in: ^6.1.0
  firebase_core: ^2.9.0
  firebase_app_check: ^0.1.1+9
  firebase_auth: ^4.4.0
  cloud_functions: ^4.1.0
  cloud_firestore: ^4.5.0
  firebase_messaging: ^14.4.0
  firebase_remote_config: ^4.0.0
  firebase_analytics: ^10.2.0
  firebase_ui_firestore: ^1.3.0
  google_maps_flutter: ^2.2.5
  flutter_facebook_auth: ^4.4.1+1
  sign_in_with_apple: ^4.3.0
  crypto: ^3.0.2

  go_router: ^6.2.0
  equatable: ^2.0.5
  easy_localization: ^3.0.1
  flutter_native_splash: ^2.2.17
  flutter_config: ^2.0.0
  intl: ^0.17.0
  shared_preferences: ^2.0.15
  package_info_plus: ^3.0.2
  streaming_shared_preferences: ^2.0.0
  url_launcher: 6.1.9
  add_2_calendar: ^2.2.3
  flutter_native_timezone: ^2.0.0
  timezone: ^0.9.0
  cached_network_image: ^3.2.3
  flutter_local_notifications: ^13.0.0
  dartz: ^0.10.1
  open_mail_app: ^0.4.5
  in_app_review: ^2.0.6
  share_plus: ^6.3.0
  geolocator: ^9.0.2
  permission_handler: ^10.3.0

  flutter_animation_progress_bar: ^2.3.1
  dotted_border: ^2.0.0+3
  font_awesome_flutter: ^10.3.0
  lottie: ^2.0.0
  flutter_rating_bar: ^4.0.1

  qr_flutter: ^4.0.0
  image_picker: ^0.8.7+4
  image_cropper: ^3.0.3
  image: ^4.0.16

I don't use multiple location plugins at the same time when testing, always one at a time.
background_locator_2 and location plugins have no issue stopping the service when the app is killed.

@Hhanri
Copy link

Hhanri commented Jun 17, 2023

@Wackymax I just found out it was caused by Firebase Messaging plugin, the FirebaseMessaging.onBackgroundMessage method reinitializes the Flutter Engine.
Therefore connectedEngines is set to 2 and connectedEngines == 0 inside canStopLocationService returns false.
Is it safe to ignore connectedEngines's value and return true in canStopLocationService ?

@Wackymax
Copy link
Contributor

Wackymax commented Jun 17, 2023 via email

@Hhanri
Copy link

Hhanri commented Jun 17, 2023

@Wackymax I need to get the device's position in background, but I still want to let the user stop the service by simply closing the app (it's not a main feature).
When I run without the foreground notification I can't retrieve the position from background and it stops by itself after a few minutes.
I forked the project and bypassed connectedEngines == 0, it stopped the service as I expected but I just wanted to make sure that it was safe to do it this way.

@Wackymax
Copy link
Contributor

Wackymax commented Jun 17, 2023 via email

@burhankhanzada
Copy link

deoes

@Wackymax I need to get the device's position in background, but I still want to let the user stop the service by simply closing the app (it's not a main feature). When I run without the foreground notification I can't retrieve the position from background and it stops by itself after a few minutes. I forked the project and bypassed connectedEngines == 0, it stopped the service as I expected but I just wanted to make sure that it was safe to do it this way.

does this fix it in the latest version coz i m also facing same issue m also using firebase cloud messaging

@burhankhanzada
Copy link

also is it possible to show a button in the notification if the user doesn't want to run this service while running the app or even when the app is terminated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android Issue is related to the Android platform. status: triage Indicates that this issue needs to be analyzed and decorated with the appropriate labels
Projects
None yet
Development

No branches or pull requests

9 participants