Skip to content

[Bug]: EXIT event is not triggered by startGeofences() in Android #1477

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

Open
2 of 3 tasks
gtran-dev opened this issue May 5, 2025 · 12 comments
Open
2 of 3 tasks

[Bug]: EXIT event is not triggered by startGeofences() in Android #1477

gtran-dev opened this issue May 5, 2025 · 12 comments
Labels
bug Something isn't working

Comments

@gtran-dev
Copy link

gtran-dev commented May 5, 2025

Required Reading

  • Confirmed

Plugin Version

4.16.9

Flutter Doctor

[✓] Flutter (Channel stable, 3.22.1, on macOS 15.3.1 24D70 darwin-arm64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2025.1.1)
[✓] VS Code (version 1.88.0)
[✓] Connected device (5 available)
[✓] Network resources

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

moto g7 play (XT1952-1)

Device operating-systems(s)

Android 10

What happened?

Hi @christocracy ,

I have two issues with geofence mode on Android. Everything works fine on iOS.

When I start the service with

bg.BackgroundGeolocation.start();

  1. The EXIT event is triggered as expected. However, when I start the service exclusively in geofence mode, the event is not triggered.

Here are the logs for two cases.

start().txt

startGeofences().txt

  1. In geofence mode, the ENTER event is not triggered correctly for a large polygon.

Note: I use Lockito to simulate the GPS position.

Thanks for your help!

Plugin Code and/or Config

bg.BackgroundGeolocation.ready(bg.Config(
        reset: true,
        enableHeadless: true,
        foregroundService: true,
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
        distanceFilter: 10.0,
        notification: bg.Notification(
            sticky: true,
            title: "${F.title} - tracking your location",
            text:
            "${F.title} accessing background location to track your location, even when it's not running."),
        backgroundPermissionRationale: bg.PermissionRationale(
            title: "Allow {applicationName} to access this device's location even when the app is closed or not in use.",
            message: "This app collects location data to change your status based on geofence.",
            positiveAction: 'Change to "{backgroundPermissionOptionLabel}"',
            negativeAction: 'Cancel'
        ),
        stopOnTerminate: false,
        startOnBoot: true,
        debug: false,
        heartbeatInterval: 60,
        preventSuspend: true,
        persistMode: bg.Config.PERSIST_MODE_ALL,
        showsBackgroundLocationIndicator: true,
        locationAuthorizationRequest: 'Always',
        logLevel: bg.Config.LOG_LEVEL_VERBOSE))
        .then((bg.State state) {
      print('[ready] - $state');
      bg.BackgroundGeolocation.startGeofences();
    });

Relevant log output

@gtran-dev gtran-dev added the bug Something isn't working label May 5, 2025
@christocracy
Copy link
Member

Geofence events can be delayed in geofence-only mode (ie: .startGeofences()).

See API docs Config.geofenceModeHighAccuracy, which will consume more power by keeping location-services ON during geofence-only mode.

@christocracy
Copy link
Member

It's a well-known with Android geofences among the entire Android development ecosystem, where they sometimes fail to fire or are delay if location-services is not active.

https://issuetracker.google.com/issues/218335535

@gtran-dev
Copy link
Author

Hi,
thanks for your reply. With the "geofenceModeHighAccuracy: true" option, more events seem to be triggered than before. I've read your thread. Unfortunately, it's a very poor move by the Android team to have this unreliable feature. It's great that you're trying to have workaround to keep the location-service ON. I have a question: If "geofenceModeHighAccuracy: true" still isn't good enough, do you think, that I should start the plugin with "start()"? Would that be more helpful? And how does the battery consumption compare to "geofenceModeHighAccuracy: true"?

@christocracy
Copy link
Member

do you think, that I should start the plugin with "start()"?

It shouldn’t make a difference.

And how does the battery consumption compare to "geofenceModeHighAccuracy: true"?

Unknown.

@gtran-dev
Copy link
Author

Hello @christocracy,

I have another problem, but it's not so big that I need to create a new ticket. On iOS, I enter the zone and receive the ENTER event. Then I close the app in the background and reopen it. The EXIT event is generated immediately, even if I'm still in the polygon. In the logs, I see that the plugin keeps throwing this error after calling ready(). do you have any ideas?

flutter: [ready] - [State enabled: true, isMoving: false, trackingMode: 0, desiredAccuracy: -1, distanceFilter: 10.0, odometer: 0.0, schedulerEnabled: false, foregroundService: null]

[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone
[Geofencing] pointInPolygon failed to find vertices for TestZone

I don't have this issue on Android. I don't look at the log, but the event isn't generated in the same test case.

@christocracy
Copy link
Member

Send me entire log file from .emailLog method.

@gtran-dev
Copy link
Author

gtran-dev commented May 13, 2025

background-geolocation.log

I attached the log file. By the way, this only happens on the real device. I'm testing on the iPhone 14 Pro. I don't have this issue in the simulator.

@christocracy
Copy link
Member

Your log-file spans a period of ~7 minutes and contains no reference to the word "TestZone".

The plugin can store up to three days worth of logs.

Go do your testing to reproduce your reported issue and provide a log file containing those errors.

@gtran-dev
Copy link
Author

Forget the name TestZone. I just renamed it to hide information. The actual error logs have the same name as the log file.

[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home
[Geofencing] pointInPolygon failed to find vertices for 14§§§Home

@christocracy
Copy link
Member

I see no reference to the text "pointInPolygon failed to find vertices for " in your log-file.

@gtran-dev
Copy link
Author

Image

I don't know why. But it appears in my flutter logs.

@christocracy
Copy link
Member

Post a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants