Skip to content

Commit bf61f1f

Browse files
committed
Reuse map fragment on orientation change
1 parent 9774607 commit bf61f1f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/src/main/java/org/nitri/opentopo/MainActivity.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ private void addMapFragment() {
8787
return;
8888
}
8989
MapFragment mapFragment;
90-
if (mGeoPointFromIntent == null)
91-
mapFragment = MapFragment.newInstance();
92-
else
90+
if (mGeoPointFromIntent == null) {
91+
mapFragment = (MapFragment) getSupportFragmentManager().findFragmentByTag(MAP_FRAGMENT_TAG);
92+
if (mapFragment == null) {
93+
mapFragment = MapFragment.newInstance();
94+
}
95+
} else {
9396
mapFragment = MapFragment.newInstance(mGeoPointFromIntent.getLatitude(), mGeoPointFromIntent.getLongitude());
97+
}
9498
getSupportFragmentManager().beginTransaction()
9599
.add(R.id.map_container, mapFragment, MAP_FRAGMENT_TAG)
96100
.commit();
@@ -148,10 +152,10 @@ public void onActivityResult(int requestCode, int resultCode,
148152
if (requestCode == READ_REQUEST_CODE && resultCode == AppCompatActivity.RESULT_OK) {
149153
if (resultData != null) {
150154
mGpxUri = resultData.getData();
155+
mZoomToGpx = true;
151156
if (mGpxUri != null) {
152157
Log.i(TAG, "Uri: " + mGpxUri.toString());
153158
parseGpx(mGpxUri);
154-
mZoomToGpx = true;
155159
}
156160
}
157161
}

0 commit comments

Comments
 (0)