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

onLocation is firing from older instances #231

Closed
raphaaugustosilva opened this issue Apr 13, 2020 · 5 comments
Closed

onLocation is firing from older instances #231

raphaaugustosilva opened this issue Apr 13, 2020 · 5 comments
Labels

Comments

@raphaaugustosilva
Copy link

raphaaugustosilva commented Apr 13, 2020

Your Environment

  • Plugin version: 1.7.1
  • Platform: Android (could not test on iOS yet)
  • OS version: All
  • Device manufacturer / model: LG Nexus 5X
  • Flutter info (flutter doctor):
    [✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale pt-BR)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)

[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.44.0)
[✓] Connected device (1 available)

• No issues found!

  • Plugin config:
  Future configureBgGeolocation() async {
    if (!_configurado) {
      bg.BackgroundGeolocation.onLocation((bg.Location location) => acaoAoReceberCoordenada(location));
      bg.BackgroundGeolocation.onGeofence((bg.GeofenceEvent geofenceEvent) => acaoAoEntrarGeofance(geofenceEvent));
      
      TransistorAuthorizationToken transistorAuthorizationToken = await TransistorAuthorizationToken.findOrCreate('myCompanyName', "myClientId");

      await bg.BackgroundGeolocation.destroyLocations();

      await bg.BackgroundGeolocation.ready(
        bg.Config(
          transistorAuthorizationToken: transistorAuthorizationToken,
          desiredAccuracy: bg.Config.DESIRED_ACCURACY_NAVIGATION,
          distanceFilter: 20,
          stopOnTerminate: true,
          startOnBoot: false,
          debug: (kReleaseMode) ? false : true,
          logLevel: (kReleaseMode) ? bg.Config.LOG_LEVEL_OFF : bg.Config.LOG_LEVEL_DEBUG,
          notification: bg.Notification(text: "Status: em movimento"),
          stationaryRadius: 25,
          locationAuthorizationRequest: "Always",
          locationAuthorizationAlert: {
            'titleWhenNotEnabled': 'Serviço de localização não habilitado',
            'titleWhenOff': 'Serviço de localização desligado',
            'instructions': 'Este aplicativo precisa usar sua localização para ter a experiência de navegação com GPS',
            'cancelButton': 'Cancelar',
            'settingsButton': 'Preferências',
          },
          params: {"usuarioId": usuarioUtilizandoGeolocalizacao?.id ?? "", "email": usuarioUtilizandoGeolocalizacao?.email ?? "", "trilhaId": this.trilhaId ?? ""},
        ),
      );
    }
  }

//The user that demands when he wants to start/stop the methods below
  
  Future iniciarCapturaGeolocalizacao() async {
    await bg.BackgroundGeolocation.start();
    bg.BackgroundGeolocation.changePace(true);
  }

  Future pararCapturaGeolocalizacao() async {
    try {
      if ((await bg.BackgroundGeolocation.state).isMoving) await bg.BackgroundGeolocation.changePace(false);
    } catch (e) {}
    await bg.BackgroundGeolocation.stop();
  }

  Future destroiGeolocalizacaoBackground() async {
    try {
      if ((await bg.BackgroundGeolocation.state).isMoving) await bg.BackgroundGeolocation.changePace(false);
    } catch (e) {}
    await bg.BackgroundGeolocation.stop();
  }

  Future<bg.Location> recuperarPosicaoAtual() async {
    try {
      return await bg.BackgroundGeolocation.getCurrentPosition(persist: false);
    } catch (e) {
      print("Erro ao recuperarPosicaoAtual. Detalhes: $e");
      return null;
    }
  }

Expected Behavior

When the .stop is invoked, then all the further locations must be destroyed

Actual Behavior

When I stop an instance, and then I start a new one, onLocation event is fired with locations from the older instance.

Steps to Reproduce

  1. From the code above, call "configureBgGeolocation" method.
  2. Call "iniciarCapturaGeolocalizacao" method.
  3. Start moving
  4. Notice that onLocation is firing correctly.
  5. Call "destroiGeolocalizacaoBackground" method.
  6. Call "configureBgGeolocation" method again
  7. Call "iniciarCapturaGeolocalizacao" method but do not move.
  8. Notice that onLocation is firing with older locations (apparently from the older instance)

Context

I'm trying to start/stop the service and capturing the locations from these user`s manual actions

@christocracy
Copy link
Member

When I stop an instance, and then I start a new one

There is no "multiple instances" of BackgroundGeolocation. It is a singleton.

Notice that onLocation is firing with older locations

This makes no sense. What makes you think the locations are "older"?

@christocracy
Copy link
Member

The plugin is like an electronic device with a power button.

#stop = power off.
#start = power on.

@christocracy
Copy link
Member

Have you read the API docs for onLocation

@stale
Copy link

stale bot commented Jun 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

@stale stale bot added the stale label Jun 12, 2020
@stale
Copy link

stale bot commented Jun 20, 2020

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

@stale stale bot closed this as completed Jun 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants