I have an app that uses google maps. I am saving the latLngBounds to variables and then to bundle to later retrieve it. My problem is that I want to save the current position of the screen and then move the camera to that LatLng. But each time when I click the marker and launch another activity and return back, the screen got centered to that clicked marker but I want to get rid of this function and make the screen return back to it's previous position.
EDIT: The problem is that my app is not recovering the data from bundle and I don't know why. Here are my methods for saving and restoring state but neither one works:
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
//requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
if (bundle!= null){
lat = bundle.getDouble("lat1",0);
lon = bundle.getDouble("lon1",0);
ne3 = bundle.getDouble("lat2",-200);
ne4 = bundle.getDouble("lon2",-200);
Log.d("tag","bundle is not null");
}
setUpMapIfNeeded();
}
@Override
public void onPause() {
super.onPause();
manager.removeUpdates(this);
}
@Override
protected void onResume() {
super.onResume();
if (bundle!= null){
lat = bundle.getDouble("lat1",0);
lon = bundle.getDouble("lon1",0);
ne3 = bundle.getDouble("lat2",-200);
ne4 = bundle.getDouble("lon2",-200);
Log.d("tag","bundle is not null");
}
setUpMapIfNeeded();
}
@Override
protected void onSaveInstanceState(Bundle bundle) {
Log.e("tag","calling onSave");
if(mMap!=null){
LatLngBounds location3 = mMap.getProjection().getVisibleRegion().latLngBounds;
double lat4 = location3.getCenter().latitude;
double lon4 = location3.getCenter().longitude;
double lat5 = location3.northeast.latitude;
double lon5 = location3.northeast.longitude;
bundle.putDouble("lat1", lat4);
bundle.putDouble("lon1",lon4);
bundle.putDouble("lat2",lat5);
bundle.putDouble("lon2",lon5);
}
super.onSaveInstanceState(bundle);
}
@Override
public void onRestoreInstanceState(Bundle bundle) {
super.onRestoreInstanceState(bundle);
if (bundle!= null){
lat = bundle.getDouble("lat1",0);
lon = bundle.getDouble("lon1",0);
ne3 = bundle.getDouble("lat2",-200);
ne4 = bundle.getDouble("lon2",-200);
Log.d("tag","bundle is not null");
}
setUpMapIfNeeded();
// ... recover more data
}
The problem seems that the bundle is somehow null when returning from the another activity