1

Is it possible to get continuous location updates in the doInBackground() method of an Async Task?

For example requestLocationUpdates() in onPreExecute() and then doing something with the location changes inside the donInBackground() method by altering the onLocationChanged() method of the listener passed as a parameter for the requestLocationUpdates() method.

How can something like this be achieved?

viperjonis
  • 40
  • 1
  • 7
  • That wouldn't work. You only need to call `requestLocationUpdates()` once. Depending on what you set for time intervals and min distance, you will get `onLocationChanged()` callbacks at some frequency until you call `removeUpdates()`. – Daniel Nugent May 10 '18 at 22:40
  • @DanielNugent So there is no way to get location changes in `doInBackground()` by overwritting the listener once it has been declared in `requestLocationUpdates()` ? – viperjonis May 10 '18 at 23:01
  • The AsyncTask class is for doing things on a background thread, and there is nothing here that needs to be on a background thread. Calling `requestLocationUpdates()` already gives you continuous location updates, just by calling the method. Take a look here for more explanation, and a solution for processing the `onLocationChanged()` events in a background thread: https://stackoverflow.com/questions/29219144/requestlocationupdates-in-separate-thread – Daniel Nugent May 10 '18 at 23:35

0 Answers0