transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
650 stars 241 forks source link

Headless vs StartBackgroundTask #1339

Closed millerf closed 3 months ago

millerf commented 3 months ago

Your Environment

• No issues found!


* Plugin config:
```dart <-- Syntax highlighting: DO NOT REMOVE -->
bg.Config(
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_MEDIUM,
        distanceFilter: 50.0,
        enableHeadless: true,
        stopOnTerminate: false,
        allowIdenticalLocations: false,
        startOnBoot: true,
        autoSync: false,
        debug: settings.test && settings.testBackgroundGeolocation,
        showsBackgroundLocationIndicator: false,
        locationAuthorizationRequest: permission,
        logLevel: bg.Config.LOG_LEVEL_VERBOSE);

Enquiry

I am working on my app https://nomad-park.com. It's for iOS and Android. And I need to send GPS data (alongside other data) to the server whenever the device is moving. Nothing original here. What I am struggling with is the distinction between background tasks and Headless. I only created an headless and i realise I do not get much data....

After reading the documentation again, I realized I was mistaken, and that I should use startBackgroundTask when onLocation is received.

That being said, it seems like startBackgroundTask also works for Android.

What is the recommended approach to make sure the location is also sent to my server (via my own logic), both when app is used and when it is in the background / stopped? on both Android and iOS?

Should I set both headless and startBackground?! or is startBackground enough?

I think there is something I might be missing.

PS: I have a license, not sure if that is the right way to access support.

christocracy commented 3 months ago

I don’t think you understand the concept of Android Headless Mode. There is nothing similar between it and .startBackgroundTask.

in fact, .startBackgroundTask can be used within a HeadlessTask.

millerf commented 3 months ago

I don’t think you understand the concept of Android Headless Mode. There is nothing similar between it and .startBackgroundTask.

You're probably right. My understanding is the headless Mode is the Foreground Service. But I might be wrong.

What I am trying to achieve is as simple as tracking the GPS position of the device whenever possible... What would be the best approach?

christocracy commented 3 months ago

My understanding is the headless Mode is the Foreground Service.

No, that’s not what it is. The plug-in doesn’t require you to register a HeadlessTask to operate when terminated. HeadlessMode is merely an event-listener to receive events when the Android app is terminated, when you have custom business logic to run. The plug-in is going to continue tracking after terminate (assuming stopOnTerminate: false), regardless if a HeadlessTask is registered or not. Headless mode is merely a convenience function for users and NOT required.

What I am trying to achieve is as simple as tracking the GPS position of the device whenever possible

That’s what the plug-in does by default, with stopOnTerminate: false.

I suggest you configure debug: true, terminate the app then go outside for a nice long walk (>= 1km). Those beeps you hear are the plug-in continuing to operate.

millerf commented 3 months ago

That clears things up! I will test it with debug on. I did not know it would work

That’s what the plug-in does by default, with stopOnTerminate: true.

Do you mean with stopOnTerminate: false?

I will test anyway. I was not aware of the beeps working when the app is terminated!!!

Thanks a lot.

millerf commented 3 months ago

I'll close (feel free to reopen if needed).