#1929 - Wiring up MapView to Activity's lifecycle methods

This commit is contained in:
Brad Leege
2015-07-24 16:37:29 -05:00
parent 53c3b0b81a
commit 955b610fc8

View File

@@ -111,6 +111,7 @@ public class MainActivity extends ActionBarActivity {
// Load the layout
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.mainMapView);
mapView.onCreate(savedInstanceState);
mapView.setOnFpsChangedListener(new MyOnFpsChangedListener());
mapView.setOnMapChangedListener(new MyOnMapChangedListener());
@@ -169,11 +170,19 @@ public class MainActivity extends ActionBarActivity {
mapView.onStart();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
}
// Called when our app goes into the background
@Override
public void onPause() {
super.onPause();
mapView.onPause();
// Cancel GPS
toggleGps(false);
}
@@ -182,15 +191,25 @@ public class MainActivity extends ActionBarActivity {
@Override
public void onResume() {
super.onResume();
mapView.onResume();
// Restart GPS
toggleGps(true);
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
// Called when we need to save instance state
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
outState.putBoolean(STATE_IS_GPS_ON, mIsGpsOn);
}