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

onLocationChanged event stop firing in backgound #397

Open
dukizwe opened this issue Jan 13, 2025 · 3 comments
Open

onLocationChanged event stop firing in backgound #397

dukizwe opened this issue Jan 13, 2025 · 3 comments
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@dukizwe
Copy link

dukizwe commented Jan 13, 2025

The onLocationChanged event triggers correctly when the app is in the foreground. However, when the app goes into the background, the event no longer fires.

According to the documentation, to ensure that the service continues running in the background, you need to set the taskRemovedBehavior property to TaskRemovedBehavior.CONTINUE_SERVICE.

I would like to confirm whether this is the default behavior or if additional adjustments are needed to make the event trigger while the app is in the background.

Platform: Android

@dukizwe dukizwe added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 13, 2025
@jokerttu jokerttu added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Jan 17, 2025
@jokerttu
Copy link
Contributor

@dukizwe Thank you for reporting this issue.

@illuminati1911 Could you please take a look?
Since TaskRemovedBehavior.CONTINUE_SERVICE is the default behavior, events should trigger while the app is in the background.

@illuminati1911
Copy link
Contributor

The onLocationChanged event triggers correctly when the app is in the foreground. However, when the app goes into the background, the event no longer fires.

According to the documentation, to ensure that the service continues running in the background, you need to set the taskRemovedBehavior property to TaskRemovedBehavior.CONTINUE_SERVICE.

I would like to confirm whether this is the default behavior or if additional adjustments are needed to make the event trigger while the app is in the background.

Platform: Android

Hey @dukizwe.

It is the default behavior and there shouldn't be a need to do anything else assuming you have started the location updates in the app. Could you test our example app and see if you face the same issue there as well?

@dukizwe
Copy link
Author

dukizwe commented Jan 26, 2025

I tested the example app, and it works perfectly. I discovered that the issue arises from the debounce code I use inside the event to prevent multiple calls. I couldn’t find a way to properly configure the interval and fastestInterval settings:

import debounce from 'lodash.debounce';
import throttle from 'lodash.throttle';

const onLocationChanged = useCallback(
   debounce(
      throttle(location => {
         console.log("onLocationChanged")
      }, 5000),
      900
   ),
   [] // Ensure this callback is stable and not recreated
);

this works perfectly in foreground but not in background

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants