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

Stopping Background Location Service and Unregistering Listeners #1536

Open
3 of 8 tasks
mayank-vinove opened this issue Jun 25, 2024 · 7 comments
Open
3 of 8 tasks
Assignees

Comments

@mayank-vinove
Copy link

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Your question

our Android application initiates background location updates upon user login. However, upon user logout, it's essential to gracefully stop the background service responsible for location updates and unregister all associated listeners to optimize resource usage and ensure proper application behavior.

So How can we stop background service and dispose all listeners ( stream) in case of user logout or we want to stop listning the location on simple button click

Version

12.0.0

@mayank-vinove
Copy link
Author

any update??

@mayank-vinove
Copy link
Author

Is there any update?

I also want cancel the foreground service when the user logs out and start it again when the user re-logs in. Additionally, the foreground service notification should also close when the service is canceled.

Is there any predefined method for this?

@mayank-vinove
Copy link
Author

@TimHoogstrate please check this.

@mayank-vinove
Copy link
Author

mayank-vinove commented Aug 8, 2024

@TimHoogstrate

Summary:
Currently, the Geolocator class does not provide a way to access the current active stream subscription. This creates challenges when attempting to manage background location updates, particularly when the app is killed and then reopened.

Proposed Enhancement:
It would be highly beneficial to have the ability to retrieve and manage the active stream subscription directly from the Geolocator class. This would allow developers to programmatically stop or cancel the foreground service or stream when the app reopened, The primary goal is to enable better control over background location updates and ensure efficient resource management.

Use Case:

Background Location Updates: When background location updates are enabled and the app is killed, there is no straightforward way to access the active stream subscription upon reopening the app. Providing access to this active stream would allow for proper management of the service.
User Logout: On user logout or any specific event, the ability to retrieve and cancel the active stream subscription would ensure that the location updates are stopped as required.

Suggested Implementation:

Introduce a method in the Geolocator class to get the current active stream subscription so it can be handle later from anywhere.

@TimHoogstrate
Copy link
Contributor

Dear @mayank-vinove,

Is cancelling the position stream not sufficient like in the example app?

Kind regards,

@TimHoogstrate TimHoogstrate self-assigned this Aug 19, 2024
@TimHoogstrate TimHoogstrate added status: needs more info We need more information before we can continue work on this issue. background-foreground-location and removed background-foreground-location labels Aug 19, 2024
@mayank250004
Copy link

If the user starts location updates and then kills the app, upon reopening, they lose access to the active stream, making it impossible to cancel.

Possible Solutions:
A. Implement a method to return the active stream so that the user can cancel it.

B. Create a method to cancel all active streams and clear the foreground service.

Note : Assume we are not using any third-party plugins like foreground_service or work_manager.

@github-actions github-actions bot removed the status: needs more info We need more information before we can continue work on this issue. label Sep 2, 2024
@anthealb
Copy link

anthealb commented Oct 7, 2024

I am facing the same issue, although in my case I'm currently testing on iOS.
If I start a stream that tracks the user in the background, and the user then puts the app in the background, when they reopen the app I find I lost my refrence to the active stream subscription and I have no way to close it.
Is there any workaround to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants