icapps / flutter-background-location-tracker

Flutter background location tracker plugin. (Android / iOS)
MIT License
31 stars 37 forks source link

infinite repeat backgroundCallback when First time only install app for any device android #62

Closed AhkamKhallaf closed 1 year ago

AhkamKhallaf commented 1 year ago

infinite repeat backgroundCallback when First time only install app for any device android , but when run application second time , it works normally , this my backgroundCallBack

@pragma('vm:entry-point')
void backgroundCallback() {
  BackgroundLocationTrackerManager.handleBackgroundUpdated(
      (BackgroundLocationUpdateData data) async {
    try {
      await providerContainer.read(currentLocationProvider).saveUserLocation(data: data);
    } catch (onError) {
      debugPrint('$onError');
    }
  });
}, 
my configuration 
  await BackgroundLocationTrackerManager.initialize(
    backgroundCallback,
    config: const BackgroundLocationTrackerConfig(
      androidConfig: AndroidConfig(
        distanceFilterMeters: 100,
        trackingInterval: Duration(minutes: 5),
        enableCancelTrackingAction: false,
      ),
      iOSConfig: IOSConfig(
        activityType: ActivityType.FITNESS,
        distanceFilterMeters: 100,
        restartAfterKill: true,
      ),
    ),
  );

@ikbendewilliam any help about this issue

ikbendewilliam commented 1 year ago

@AhkamKhalaaf Do you do WidgetsFlutterBinding.ensureInitialized(); before the await BackgroundLocationTrackerManager.initialize?

ikbendewilliam commented 1 year ago

@AhkamKhalaaf I see you've already opened an issue for this, we'll discuss it further there to prevent confusion.

ikbendewilliam commented 1 year ago

duplicate of #54