Android Nougat compatibility: onstart/onstop on MapView (#6830)
* introduce onstart/onstop on MapView * update wear module * update fragments * update changeling
This commit is contained in:
@@ -23,7 +23,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
* <li> You can unregister a {@link LocationListener} with {@link #removeLocationListener(LocationListener)}.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Note: If registering a listener in your Activity.onResume() implementation, you should unregister it in Activity.onPause().
|
||||
* Note: If registering a listener in your Activity.onStart() implementation, you should unregister it in Activity.onStop().
|
||||
* (You won't receive location updates when paused, and this will cut down on unnecessary system overhead).
|
||||
* Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back in the history stack.
|
||||
* </p>
|
||||
|
||||
@@ -159,6 +159,7 @@ public final class MapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
map.onStart();
|
||||
map.getMapAsync(onMapReadyCallback);
|
||||
}
|
||||
|
||||
@@ -197,6 +198,7 @@ public final class MapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
map.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -160,6 +160,9 @@ public class MapView extends FrameLayout {
|
||||
private List<OnMapReadyCallback> onMapReadyCallbackList;
|
||||
private SnapshotRequest snapshotRequest;
|
||||
|
||||
private boolean onStartCalled;
|
||||
private boolean onStopCalled;
|
||||
|
||||
@UiThread
|
||||
public MapView(@NonNull Context context) {
|
||||
super(context);
|
||||
@@ -573,43 +576,18 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onDestroy()} or {@link Fragment#onDestroy()}.
|
||||
* You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}
|
||||
*/
|
||||
@UiThread
|
||||
public void onDestroy() {
|
||||
destroyed = true;
|
||||
nativeMapView.terminateContext();
|
||||
nativeMapView.terminateDisplay();
|
||||
nativeMapView.destroySurface();
|
||||
nativeMapView.destroy();
|
||||
nativeMapView = null;
|
||||
}
|
||||
public void onStart() {
|
||||
onStartCalled = true;
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onPause()} or {@link Fragment#onPause()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onPause() {
|
||||
// Unregister for connectivity changes
|
||||
if (connectivityReceiver != null) {
|
||||
getContext().unregisterReceiver(connectivityReceiver);
|
||||
connectivityReceiver = null;
|
||||
}
|
||||
|
||||
myLocationView.onPause();
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onResume()} or {@link Fragment#onResume()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onResume() {
|
||||
// Register for connectivity changes
|
||||
connectivityReceiver = new ConnectivityReceiver();
|
||||
getContext().registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
|
||||
|
||||
nativeMapView.update();
|
||||
myLocationView.onResume();
|
||||
myLocationView.onStart();
|
||||
|
||||
// In case that no style was set or was loaded through MapboxMapOptions
|
||||
if (!styleWasSet) {
|
||||
@@ -617,6 +595,61 @@ public class MapView extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onResume()} or {@link Fragment#onResume()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onResume() {
|
||||
if (!onStartCalled) {
|
||||
// TODO: 26/10/16, can be removed after 5.0.0 release
|
||||
throw new IllegalStateException("MapView#onStart() was not called. " +
|
||||
"You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onPause()} or {@link Fragment#onPause()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onPause() {
|
||||
// replaced by onStop in v5.0.0, keep around for future development
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onStop() {
|
||||
onStopCalled = true;
|
||||
|
||||
// Unregister for connectivity changes
|
||||
if (connectivityReceiver != null) {
|
||||
getContext().unregisterReceiver(connectivityReceiver);
|
||||
connectivityReceiver = null;
|
||||
}
|
||||
|
||||
myLocationView.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
* You must call this method from the parent's {@link Activity#onDestroy()} or {@link Fragment#onDestroy()}.
|
||||
*/
|
||||
@UiThread
|
||||
public void onDestroy() {
|
||||
if (!onStopCalled) {
|
||||
// TODO: 26/10/16, can be removed after 5.0.0 release
|
||||
throw new IllegalStateException("MapView#onStop() was not called. " +
|
||||
"You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}.");
|
||||
}
|
||||
|
||||
destroyed = true;
|
||||
nativeMapView.terminateContext();
|
||||
nativeMapView.terminateDisplay();
|
||||
nativeMapView.destroySurface();
|
||||
nativeMapView.destroy();
|
||||
nativeMapView = null;
|
||||
}
|
||||
|
||||
void setFocalPoint(PointF focalPoint) {
|
||||
if (focalPoint == null) {
|
||||
// resetting focal point,
|
||||
|
||||
@@ -167,6 +167,7 @@ public class SupportMapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
map.onStart();
|
||||
map.getMapAsync(onMapReadyCallback);
|
||||
}
|
||||
|
||||
@@ -205,6 +206,7 @@ public class SupportMapFragment extends Fragment {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
map.onStop();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -321,7 +321,7 @@ public class MyLocationView extends View {
|
||||
setBearing(position.bearing);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
public void onStart() {
|
||||
if (myBearingTrackingMode == MyBearingTracking.COMPASS) {
|
||||
compassListener.onResume();
|
||||
}
|
||||
@@ -330,7 +330,7 @@ public class MyLocationView extends View {
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
public void onStop() {
|
||||
compassListener.onPause();
|
||||
toggleGps(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user