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
Comments
I add and it look like this
but I'am not sure, that this is correct for rest of functionality |
This doesnt work for me i still get leaks |
Now i get this message also |
Same error, but to me it happens on app startup. |
@mvanbeusekom I will have a look at it |
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. |
@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. |
Ok that is a separate issue that I can help fix
… On 02 Mar 2022, at 16:54, Bujdy ***@***.***> wrote:
@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.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.
|
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? |
I am not going to have time to fix it this week, but the fix would be to stop the service when the activity is detached from the engine and also unbinding the service connect.
For now background will work when the app is minimised, and if wake lock is true it will also stay alive when the phone goes to sleep. If the system comes under memory pressure Android may still choose to kill the activity which will terminate the application which will stop the foreground service.
… On 03 Mar 2022, at 09:29, Bujdy ***@***.***> wrote:
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?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.
|
PR to unbind the service is up |
@Wackymax is it only happening to me? |
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 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. |
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. |
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 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? |
Yes very happy! |
Good job guys, everything is working, app is being killed. Only one problem, i get this error when i kill app.
|
Seems like it is trying to unregister a receiver that is already |
That explains the difference in the logs, thanks for confirming. No need to remove it and test again that shouldn't make a difference. |
So other plugins got same problem? |
@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 ( |
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 |
So there isn´t way to fix this and kill app? Or are you still investigating this issue? |
Any news? @Wackymax @mvanbeusekom |
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.
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. |
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. |
But it still wont kill the application when you are trying to close it. |
@Wackymax @mvanbeusekom is there anything you tried in past days? |
Hi,
I haven't since I can't reproduce it on my side.
… On 24 Mar 2022, at 09:09, Bujdy ***@***.***> wrote:
@Wackymax @mvanbeusekom is there anything you tried in past days?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.
|
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. |
Any news on this? |
I have tried with the latest updates in the Android package and no longer experience any issues anymore. |
It's a single log entry I added to confirm the code reached the end of the destroy method. Rest of the code is the same as the master branch.
… On 10 Mar 2022, at 12:53, Maurits van Beusekom ***@***.***> wrote:
I noticed your logs contain the message "Destroyed location service", I am not able to find this message in my code base. Could it be you have a slightly different version?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.
|
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 |
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 |
I'm still facing this issue when I swipe the app (geolocator 9.0.2 with geolocator_android 4.1.9).
|
@Hhanri did you configure a timeout on the future returned? If so you should have received a |
@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 |
Based on the logs you sent it seems like it's staying connected because there are multiple flutter engines alive, almost like there is a background process running with another flutter instance.What other plugins do you have installed and active?On 15 Jun 2023, at 17:17, Hanri ***@***.***> wrote:
@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.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
EDIT: I just tested Here are all the dependencies I'm using
I don't use multiple location plugins at the same time when testing, always one at a time. |
@Wackymax I just found out it was caused by Firebase Messaging plugin, the |
We can't do it in the official lib because it's needed for when geolocator is running in background plugins which is expected behavior.We would have to change the code to see which engine is currently using location services and possibly stop it when we see that engine gets destroyed.I do wonder though, if you want to location services to stop with the activity then why are you setting the foreground notification in the first place? If you do not set it then the service should behave correctly and stop when the activity is stopped.On 17 Jun 2023, at 16:23, Hanri ***@***.***> wrote:
@Wackymax I just found out it was caused by Firebase Messaging plugin, the FirebaseMessaging.onBackgroundMessage method reinitializes the Flutter Engine.
Therefore the connectedEngines is set to 2 and ``connectedEngines == 0insidecanStopLocationService``` returns false.
Is it safe to ignore ```connectedEngines```'s value and return true in ```canStopLocationService``` ?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@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). |
Yeah it should be safe to do that. On 17 Jun 2023, at 16:54, Hennie Brink ***@***.***> wrote:We can't do it in the official lib because it's needed for when geolocator is running in background plugins which is expected behavior.We would have to change the code to see which engine is currently using location services and possibly stop it when we see that engine gets destroyed.I do wonder though, if you want to location services to stop with the activity then why are you setting the foreground notification in the first place? If you do not set it then the service should behave correctly and stop when the activity is stopped.On 17 Jun 2023, at 16:23, Hanri ***@***.***> wrote:
@Wackymax I just found out it was caused by Firebase Messaging plugin, the FirebaseMessaging.onBackgroundMessage method reinitializes the Flutter Engine.
Therefore the connectedEngines is set to 2 and ``connectedEngines == 0insidecanStopLocationService``` returns false.
Is it safe to ignore ```connectedEngines```'s value and return true in ```canStopLocationService``` ?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
deoes
does this fix it in the latest version coz i m also facing same issue m also using firebase cloud messaging |
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? |
🐛 Bug Report
I wanted to try to listen to locations even after i terminate app so i added
to settings. But when i terminate the app i get this leak
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:
The text was updated successfully, but these errors were encountered: