Reputation: 11
I have a google maps with different markers in my application. When I tap a marker (onTap()), a new detail window appears and theres some information about the specific location. My problem is that when I click back, the whole map redraws. I can see it, because the shadow of the markers is getting darker every time I open an infowindow and click the back button. Furthermore, it always zooms back to my current location (-> triggers the whole onResume() method).
How can I avoid that the map gets redrawn every time?
Overlay item class:
@Override
public boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
Item item = map.get(item);
Intent intent = new Intent();
intent.setClass(mContext, SomeExampleClass.class);
mContext.startActivity(intent);
return true;
}
Map Class:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
mapView = (MapView) findViewById(R.id.mainmap);
mapView.invalidate();
mapView.setBuiltInZoomControls(true);
dbZugriff = new DatabaseAccess(this);
mylocationoverlay = new MyLocationOverlay(this, mapView);
mc = mapView.getController();
}
@Override
protected void onResume() {
super.onResume();
mylocationoverlay.enableMyLocation();
mapView.getOverlays().add(mylocationoverlay);
mylocationoverlay.runOnFirstFix(new Runnable(){
@Override
public void run() {
GeoPoint myLocation = mylocationoverlay.getMyLocation();
mc.animateTo(myLocation);
mc.setZoom(16);
mapView.postInvalidate();
}
});
SharedPreferences prefs = getSharedPreferences("prefs",Context.MODE_PRIVATE);
SpecialitiesSelection specialitiesSelection = SpecialitiesSelection.loadFromPreferences(prefs, "");
Cursor resultat = dbZugriff.createCursor(specialitiesSelection);
mapOverlays = mapView.getOverlays();
List<Item> list = new ArrayList<Item>();
if (resultat.moveToFirst()){
do{
Item daten = Item.createFromCursor(resultat);
list.add(daten);
}
while(resultat.moveToNext());
}
Drawable drawable = this.getResources().getDrawable(R.drawable.ic_launcher);
itemizedoverlay = new ItemOverlay(drawable,this,list);
mapOverlays.add(itemizedoverlay);
}
Upvotes: 1
Views: 1083
Reputation: 1007359
Your onResume()
is being called every time you press BACK from SomeExampleClass. In onResume()
, you are doing everything you say that you do not want to have happen. Hence, move this code someplace else (e.g., onCreate()
).
Upvotes: 2