xamarin.maps: How to disable getting geolocation position when app is backgrounded

PhenmanPhenman USMember ✭✭

Hello everyone. Could you help me for this task? I need to disable getting geolocation position in OnSleap method and to enable this in OnResume method in order to avoid increased battery consumption when I have other application on foreground.

Answers

  • JohnHardmanJohnHardman GBUniversity mod
    edited February 2018

    @Phenman - I cannot check right now, but wouldn't setting the AllowsBackgroundUpdates property of the geolocator to false do that?

    Alternatively, you could call StopListeningAsync from OnSleep, and StartListeningAsync from OnResume. My preference would be to use AllowsBackgroundUpdates though.

    (I am assuming that you are using Plugin.Geolocator)

  • PhenmanPhenman USMember ✭✭
    edited February 2018

    @JohnHardman said:
    @Phenman - I cannot check right now, but wouldn't setting the AllowsBackgroundUpdates property of the geolocator to false do that?

    Alternatively, you could call StopListeningAsync from OnSleep, and StartListeningAsync from OnResume. My preference would be to use AllowsBackgroundUpdates though.

    (I am assuming that you are using Plugin.Geolocator)

    hmm... I use Plugin.Geolocator, but I can't see AllowsBackgroundUpdates in CrossGeolocator.Current. Furthermore I already use StartListeningAsync and StopListeningAsync and this methods are works fine. But there are geolocation icon in statusbar and increased battery consumption anyway.
    I guess that my problem linked with xamarin.maps or some system settings, because geolocation icon appears in android statusbar aleady at application launch screen, and disappear when application is closed (not backgrounded).

  • JohnHardmanJohnHardman GBUniversity mod

    @Phenman said:
    hmm... I use Plugin.Geolocator, but I can't see AllowsBackgroundUpdates in CrossGeolocator.Current.

    What version of the plugin are you using? I use CrossGeolocator.Current.AllowsBackgroundUpdates using Xam.Plugin.Geolocator v3.0.4

  • PhenmanPhenman USMember ✭✭

    @JohnHardman said:

    @Phenman said:
    hmm... I use Plugin.Geolocator, but I can't see AllowsBackgroundUpdates in CrossGeolocator.Current.

    What version of the plugin are you using? I use CrossGeolocator.Current.AllowsBackgroundUpdates using Xam.Plugin.Geolocator v3.0.4

    latest stable 4.2.0

  • JohnHardmanJohnHardman GBUniversity mod

    @Phenman - Looking at the documentation at https://jamesmontemagno.github.io/GeolocatorPlugin/BackgroundUpdates.html it would appear that AllowsBackgroundUpdates has been renamed to AllowBackgroundUpdates

  • PhenmanPhenman USMember ✭✭

    @JohnHardman said:
    @Phenman - Looking at the documentation at https://jamesmontemagno.github.io/GeolocatorPlugin/BackgroundUpdates.html it would appear that AllowsBackgroundUpdates has been renamed to AllowBackgroundUpdates

    Thank you! I set up AllowBackgroundUpdates to "false" in ListenerSettings, but there is no changes. Geolocation icon is in the system statusbar anyway.

  • JohnHardmanJohnHardman GBUniversity mod

    @Phenman - If you comment out uses of Xamarin.Forms.Maps so that just the Xam.Plugin.Geolocator is in use, do you still see the icon when the app is backgrounded? If so, you might want to log an issue against the plugin.

Sign In or Register to comment.