flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

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

Open gtran-dev opened this issue 8 months ago • 13 comments

Required Reading

  • [x] 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
  • [x] 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 avatar May 05 '25 09:05 gtran-dev

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 avatar May 05 '25 14:05 christocracy

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

christocracy avatar May 05 '25 14:05 christocracy

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"?

gtran-dev avatar May 06 '25 08:05 gtran-dev

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.

christocracy avatar May 06 '25 09:05 christocracy

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.

gtran-dev avatar May 13 '25 13:05 gtran-dev

Send me entire log file from .emailLog method.

christocracy avatar May 13 '25 13:05 christocracy

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.

gtran-dev avatar May 13 '25 14:05 gtran-dev

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.

christocracy avatar May 13 '25 14:05 christocracy

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

gtran-dev avatar May 13 '25 14:05 gtran-dev

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

christocracy avatar May 13 '25 14:05 christocracy

Image

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

gtran-dev avatar May 13 '25 14:05 gtran-dev

Post a new issue.

christocracy avatar May 13 '25 14:05 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jun 13 '25 02:06 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 27 '25 02:06 github-actions[bot]