-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
[Bug]: The app is still running in background event if it's killed #1395
Comments
Dear @robpot95, Is this also happening in the example app? Or do you have some minimal steps to reproduce or perhaps a little example app/code? Kind regards, |
Hello, I have not tested on the example project. But i've searched bit aroud issues in the github. Some say it may be that it attach to the FCM background service when you try to kill the app. Also this happens only if i configure |
Same thing here, the
|
Well the problem is that the app does not get killed and somehow the geolocator attach itself to something else to keep it self alive. |
Thank you for reporting this issue, I have labelled it as a bug and added it to our backlog. |
This happens because we do flutter engine reference counting to keep the location service alive when location is used in conjunction with another package like flutter_background so that location service can be used in Android Services and not be dependent on an Activity that can be killed by Android. My suggestion would be that you listen to the activity lifecycle in Flutter and cancel your location stream when the activity is killed. |
Flutter's lifecycle management This causes the message "running in background" still showing when the app is terminated by the user and it stays forever unless user force stops the app. Can we use |
Hi all, I was looking into this and I noticed that the geolocator keeps hold of the Unfortunately this is a bit difficult for me to test, is someone willing to verify if this issue still occurs when using version 4.5.2 of the geolocator_android package? |
I doubt that is what's causing this. It would be the reference counting of the active flutter engines doing this.One possible way to solve this would be to keep a smarter reference knowing about the instance of the service using geolocator rather than just plain service counting.On 07 Feb 2024, at 12:36, Maurits van Beusekom ***@***.***> wrote:
Hi all,
I was looking into this and I noticed that the geolocator keeps hold of the FlutterPluginBinding instance after the onDetachedFromActivity method is being called. In the permission_handler plugin this resulted into leaking the activity which I think might also have an impact on this issue.
Unfortunately this is a bit difficult for me to test, is someone willing to verify if this issue still occurs when using version 4.5.2 of the geolocator_android package?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
I've tried updating the geolocator_android package to version 4.5.2 in my environment, but unfortunately, I haven't noticed any changes regarding the issue. |
@mvanbeusekom Any insights or alternative solutions to circumvent this issue would be immensely appreciated. We're eager to resolve this as smoothly and swiftly as possible for the benefit of our users. |
I think there is a misunderstanding here. If you want the location services to stop when the application is killed then do not configure a foreground notification. The intention of that is to increase the priority of the flutter activity to try and not have it killed. If you do need the location in the background then use a background service plugin that will start a separate background service. Otherwise, remove the foreground notification config so that the location service can shut down when the activity is killed. |
In our app we need to track location updates when the app is running (whether foreground or minimzed). For that, we are utilizing the foreground service as I understand from the android docs that this is the way to do it (https://codelabs.developers.google.com/codelabs/while-in-use-location/#2) under Services, foreground services, and binding section. We do not required location tracking when the app is killed so from my understanding we should not declarate the background location permission as this requires extra approval from Google.
Edit: When location service is started, swiping the app away (regardless whether it was foreground or minimized) keeps the location notification on. The log from geolocator says: There is still another flutter engine connected, not stopping location service. As I mentioned previously, we cannot rely on lifecycle events to stop the service on terminate events because these events are not raised when the app is terminated. |
You can still use the flutter background plugin to accomplished this. It will be a lot more reliable than just using the foreground notification built in with this package.On 22 Mar 2024, at 22:00, Alaa Masoud ***@***.***> wrote:
@Wackymax
In our app we need to track location updates when the app is running (whether foreground or minimzed). For that, we are utilizing the foreground service as I understand from the android docs that this is the way to do it (https://codelabs.developers.google.com/codelabs/while-in-use-location/#2) under Services, foreground services, and binding section. We do not required location tracking when the app is killed so from my understanding we should not declarate the background location permission as this requires extra approval from Google.
When the app is in foreground and the user swipes it away (terminates it) the location service is stopped. However, when it is minimzed and the user swipes it away the location service is still on and the location notification still persists for the user.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I just read about If set, the service will automatically be stopped by the system if the user removes a task that is rooted in one of the application's activities Maybe if this is defined in the manifest file as follows: <service
android:enabled="true"
android:exported="false"
android:foregroundServiceType="location"
+ android:stopWithTask="true"
android:name=".GeolocatorLocationService"/> It will stop the service when the app is killed? This SO answer suggests the same. |
so, is this working? |
We can't do this globally for all apps that use this library. If you don't need background location then don't pass in the foreground notification or override the geolocatoe service descriptor in the manifest to add this attribute for your app only.On 08 May 2024, at 10:08, Tarun-kumar-koda ***@***.***> wrote:
I just read about stopWithTask flag in the android docs with the following comment:
If set, the service will automatically be stopped by the system if the user removes a task that is rooted in one of the application's activities
Maybe if this is defined in the manifest file as follows:
<service
android:enabled="true"
android:exported="false"
android:foregroundServiceType="location"
+ android:stopWithTask="true"
android:name=".GeolocatorLocationService"/>
It will stop the service when the app is killed?
This SO answer suggests the same.
so, is this working?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Please check the following before submitting a new issue.
Please select affected platform(s)
Steps to reproduce
Just have notification configured and run the app. When you kill it you get:
There is still another flutter engine connected, not stopping location service
Expected results
The app should be killed and notification should be removed
Actual results
The app still is running and notification is still there. This is draining users battery.
Code sample
Code sample
[Paste your code here]
Screenshots or video
Screenshots or video demonstration
[Upload media here]
Version
10.1.0
Flutter Doctor output
Doctor output
[Paste your output here]
The text was updated successfully, but these errors were encountered: