Forum Xamarin Xamarin.Android

Xamarin Android device performance issues in the background

Billy12ShovelsBilly12Shovels USUniversity ✭✭✭

Hello,

I am currently testing an app that tracks location in the background. On certain devices, such as a Samsung 8.0, the app only gets the users location every 10 minutes or so in the background. The app has worked in the past on the same device.

Here is my code for the Location Manager:

    LocationManager manager = (LocationManager)MainActivity.instance.GetSystemService(Context.LocationService);

    Listener listener = new Listener();

...

            Device.BeginInvokeOnMainThread(() =>
            {  
                string provider = LocationManager.GpsProvider;

                manager.RequestLocationUpdates(provider, 5000, 0, listener);
            });

Listener Class:

public class Listener : Java.Lang.Object, ILocationListener
{
    public Listener()
    {

    }

    public Listener(IntPtr a, JniHandleOwnership b) : base(a, b)
    {

    }

    public IntPtr Handle
    {
        get;
    }

    public void Dispose()
    {

    }

    public void OnLocationChanged(Android.Locations.Location location)
    {
        App.position = new Plugin.Geolocator.Abstractions.Position()
        {
            Altitude = location.Altitude,
            Latitude = location.Latitude,
            Longitude = location.Longitude,
            Accuracy = location.Accuracy,
        };

        MessagingCenter.Send<App>(App.instance, "GPS");
    }

    public void OnProviderDisabled(string provider)
    {

    }

    public void OnProviderEnabled(string provider)
    {

    }

    public void OnStatusChanged(string provider, [GeneratedEnum] Availability status, Bundle extras)
    {

    }
}

Is there updates to Android running location services in the background for 8.0? Or a certain runtime permission I need to request?

Thanks for the help.

Sign In or Register to comment.