2013-02-11 24 views
7

Aygıt döndürüldüğünde SupportMapFragment'in performansını artırmaya çalışıyorum. Parça yeniden oluşturulmalı gibi görünüyor. Bundan emin değilim, ancak cihaz döndürüldüğünde, harita karoları yeniden yüklenmelidir. Tüm harita parçasının parçayı yeniden oluşturmaya gerek kalmadan yeniden tutulması ve yeniden kullanılması, performans açısından mantıklı olacaktır. Bunun hakkında herhangi bir fikir takdir edilecektir.Android Maps Geri Dönüşüm V2 SupportMapFragmenti döndürürken

SupportMapFragment öğesini xml olarak ve api belgelerinde anlatıldığı gibi SetupMapIfNeeded() kullanarak bildiriyorum.

private void setUpMapIfNeeded() { 
    // Do a null check to confirm that we have not already instantiated the 
    // map. 
    if (mMap == null) { 
     // Try to obtain the map from the SupportMapFragment. 
     mMap = ((SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map)).getMap(); 
     // Check if we were successful in obtaining the map. 
     if (mMap != null) { 
      setUpMap(); 
     } 
    } 
} 
+0

bu Partick ile herhangi bir yerde var mı? –

cevap

10

Örneklerden RetainMapActivity sınıfına bakın. ÇALIŞIYOR bir cazibe gibi. İşte edilir:

public class RetainMapActivity extends FragmentActivity { 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.basic_demo); 

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 

    if (savedInstanceState == null) { 
     // First incarnation of this activity. 
     mapFragment.setRetainInstance(true); 
    } else { 
     // Reincarnated activity. The obtained map is the same map instance in the previous 
     // activity life cycle. There is no need to reinitialize it. 
     mMap = mapFragment.getMap(); 
    } 
    setUpMapIfNeeded(); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    setUpMapIfNeeded(); 
} 

private void setUpMapIfNeeded() { 
    if (mMap == null) { 
     mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
       .getMap(); 
     if (mMap != null) { 
      setUpMap(); 
     } 
    } 
} 

private void setUpMap() { 
    mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); 
} 

}

+0

Örneklerde bunu kaçırdım! teşekkürler – Patrick

+0

ama işaretleyiciyi yeniden çizmeniz gerekiyor! sadece harita durumunu (zoom, pozisyon vb ..) tutun ama işaretleyiciler değil polyno ... – Xenione

+0

Bu çözüm işe yarıyor gibi görünüyor. Asynk yöntemini kullanmış olsam bile. Ama 7 rotasyondan sonra harita çok gecikti – user3528466

İlgili konular