seididieci / capacitor-backround-geolocation

Ionic capacitor backgroung geolocation Plugin
MIT License
12 stars 2 forks source link

BackgroundLocation service starts automatically even when it is false by configuration. #10

Closed SalahAdDin closed 3 years ago

SalahAdDin commented 3 years ago

Hi,

I'm initializing this plugin with the application itself and later i add a new Listener as follows:

  useEffect(() => {
    fcmService.init()
    geoLocationService.init()
    loadUserData()
    loadConfData()

    geoLocationService.getLocation((location) => {

        console.log("Calling the listener from MapView component")
      if (location)
        setDeliveryManLocation({
          id: 0,
          name: "Me",
          lat: location.latitude,
          lng: location.longitude,
        })
    })
  }, [])

The initialization function is as follows:

const init = () => {
  BackgroundGeolocation.initialize({
    notificationText: "Your app is running, tap to open.",
    notificationTitle: "App Running",
    updateInteval: 10000,
    requestedAccuracy: 102,
    // Small icon has to be in 'drawable' resources of your app
    // if you does not provide one (or it is not found) a fallback icon will be used.
    smallIcon: "ic_small_icon",
    // Start getting location updates right away. You can set this to false or not set at all (se below).
    startImmediately: false,
  })

  BackgroundGeolocation.addListener("onPermissions", (data: BgPermissions) => {
    console.log("BGLocation permissions:", data)

    // Do something with data
  })
}

There is also a single toggle button which stops and starts the service when toggling.

To Reproduce Steps to reproduce the behavior:

  1. Launch the application.
  2. Go to device inspector in the browser and check the logs.
  3. Go to the button in the application and do click on it (check the logs).
  4. Do click in the button again and see how the service is stoped.

Expected behavior It shouldn't start till the user do click in the button(which starts the service).

Screenshots The next is a screenshot from the debug console(i'm using device inspector to see logs from an emulator): Captura de Pantalla 2020-10-28 a la(s) 19 43 37 As you can follow, before to user clicking on the button(to start the service) the console already is showing a task is being launched by the service. Then, when user clicks the first time it continue running, and when it does click again the service is stoped, to be re activated by a new click and deactivated again.

Due to this behaviour I think, even when there is a condition to breaks if the service was not started, adding a new listener on location will start the service, but why?

Desktop (please complete the following information):

Smartphone (please complete the following information):

SalahAdDin commented 3 years ago

It seems restart the application has solve this problem.

If i see this again, i will re open this bug again.