问题描述:

My app works like this:

1- OnCreate: creates a google map

2- OnStart: add cluster items from sqlite database and show them on map

3- OnResume: an asynctask updates the sqlite database getting the data from internet and refreshes the activity

Everything works greate but if the user uses the app with a low internet connection and restarts the activity (by rotating the screen) before the async is finished, the map is recreated but markers dont show until async finishes.

Of course i want the markers to be shown all the time regardless if the async has finished or not.

I think there is a theorical explanation to this behavior so maybe i dont need to post any code, but if you need some code anyway ask me for it.

Thank you!

Edited:

protected void onStart(){

super.onStart();

updateMarkers();

}

public void updateMarkers(){

mClusterManager.clearItems();

String[] campos = new String[] { "id", "lat", "longi" };

String[] arg = new String[] {"borrado"};

Cursor c = db.query("Sordos", campos, "estado <> ?", arg, null, null, null);

if (c.moveToFirst()) {

// Recorremos el cursor hasta que no haya más registros

do {

int id = c.getInt(0);

String lat = c.getString(1);

String longi = c.getString(2);

Double l1 = Double.parseDouble(lat);

Double l2 = Double.parseDouble(longi);

MyItem offsetItem = new MyItem(new LatLng(l1, l2), id);

mClusterManager.addItem(offsetItem);

} while (c.moveToNext());

mClusterManager.cluster();

}

}

相关阅读:
Top