• 12

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I want to get current location, when app went into sleep mode or Background.Currently i am using > Plugin.Geolocator.CrossGeolocator.Current DLL in App OnSleep() , But Its Working Till Android 8.1 but Android Pie Not updating current Location Values.. How to Achieve in Android Pie?

Sample Code :

 protected override async void OnSleep()
 var minute = TimeSpan.FromSeconds(30);
 Device.StartTimer(minute, () =>
 await Task.Run(async () =>
 TimeSpan t = TimeSpan.FromSeconds(10);
 var locator = Plugin.Geolocator.CrossGeolocator.Current;
 locator.DesiredAccuracy = 5;
 var position = await locator.GetPositionAsync(timeout: t); 
 //API Method

You can not just spin up a thread and expect it to keep running after the OS places the app into the background or battery saving mode.

You will have to setup an Android Service (and foreground it) at a minimum to handle your location updates.

Background Execution Limits


Foreground Services

Schedule tasks with WorkManager

  • 1
Reply Report
      • 1
    • Thanks a lot i will try with help of service. One more doubt its possible to stop the Running Service at time of App Killing?
      • 2
    • @AnbuMani Certainly, killing the app's process will kill everything. You can look at using WorkManager to restart your Service on a periodic basis, or by sending a remote notification to the device, etc... but there is never a guarantee that it will run constantly, that is just not how Android apps are designed to execute.