I’m doing an app which use the new Google Maps V2, when the Map Camera moves, I need to reload the points to the new camera position, I do it with a asynctask.
The problem is when I move the camera position multiple times, app loads the points multiples times. So, I cancel the async task when the camera is moved and I don’t load new point until the task is cancelled. I have an empty while loop to do it, Is there a better solution to do it?
// LOAD NEW POIS ASYNC
private void updatePoisInMap( ){
....
if (refresh_pois_async != null) {
refresh_pois_async.cancel(true);
while (!refresh_pois_async.isCancelled()) {
}
}
refresh_pois_async = new RefreshPoisAsync( ).execute( lowerLeftCorner, topRightCorner);
}
Actually, I don’t think your while loop will work, or at least not as you would expect it to. The AsyncTask.isCancelled() method is normally used inside the doInBackground() method, to support early cancellation. You have several options to do what you want: