diff --git a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationActivity.java b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationActivity.java index fc05506df8e..301592d0783 100644 --- a/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationActivity.java +++ b/libandroid-navigation-ui/src/main/java/com/mapbox/services/android/navigation/ui/v5/NavigationActivity.java @@ -22,6 +22,7 @@ public class NavigationActivity extends AppCompatActivity implements OnNavigationReadyCallback, NavigationListener { private NavigationView navigationView; + private boolean isConfigurationChange; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -31,6 +32,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { navigationView = findViewById(R.id.navigationView); navigationView.onCreate(savedInstanceState); navigationView.getNavigationAsync(this); + isConfigurationChange = savedInstanceState != null; } @Override @@ -69,8 +71,10 @@ protected void onDestroy() { public void onNavigationReady() { NavigationViewOptions.Builder options = NavigationViewOptions.builder(); options.navigationListener(this); - extractRoute(options); - extractCoordinates(options); + if (!isConfigurationChange) { + extractRoute(options); + extractCoordinates(options); + } extractConfiguration(options); navigationView.startNavigation(options.build()); } diff --git a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/MapboxNavigation.java b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/MapboxNavigation.java index f605cae6101..4e8d10fd20c 100644 --- a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/MapboxNavigation.java +++ b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/MapboxNavigation.java @@ -390,7 +390,6 @@ public void endNavigation() { context.unbindService(this); isBound = false; navigationEventDispatcher.onNavigationEvent(false); - navigationTelemetry.endSession(); } } diff --git a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationLifecycleMonitor.java b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationLifecycleMonitor.java index 663d48fdac7..52df55abfbb 100644 --- a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationLifecycleMonitor.java +++ b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationLifecycleMonitor.java @@ -54,10 +54,8 @@ public void onActivityPaused(Activity activity) { @Override public void onActivityDestroyed(Activity activity) { - if (activity.isChangingConfigurations()) { - NavigationTelemetry.getInstance().onConfigurationChange(); - } if (activity.isFinishing()) { + NavigationTelemetry.getInstance().endSession(activity.isChangingConfigurations()); activity.getApplication().unregisterActivityLifecycleCallbacks(this); } } diff --git a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationTelemetry.java b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationTelemetry.java index 328f9dbbd34..bbf86559b22 100644 --- a/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationTelemetry.java +++ b/libandroid-navigation/src/main/java/com/mapbox/services/android/navigation/v5/navigation/NavigationTelemetry.java @@ -146,9 +146,6 @@ void initialize(@NonNull Context context, @NonNull String accessToken, validateAccessToken(accessToken); - // Setup the listeners - initEventDispatcherListeners(navigation); - MapboxNavigationOptions options = navigation.options(); // Set sdkIdentifier based on if from UI or not String sdkIdentifier = updateSdkIdentifier(options); @@ -168,6 +165,8 @@ void initialize(@NonNull Context context, @NonNull String accessToken, isInitialized = true; } + // Setup the listeners + initEventDispatcherListeners(navigation); } /** @@ -200,16 +199,16 @@ void startSession(DirectionsRoute directionsRoute) { .mockLocation(metricLocation.getLocation().getProvider().equals(MOCK_PROVIDER)) .rerouteCount(0) .build(); - } else { - isConfigurationChange = false; } + isConfigurationChange = false; } /** * Flushes any remaining events from the reroute / feedback queue and fires * a cancel event indicating a terminated session. */ - void endSession() { + void endSession(boolean isConfigurationChange) { + this.isConfigurationChange = isConfigurationChange; if (!isConfigurationChange) { if (navigationSessionState.startTimestamp() != null) { flushEventQueues(); @@ -274,10 +273,6 @@ void updateLocationEngine(LocationEngine locationEngine) { } } - void onConfigurationChange() { - isConfigurationChange = true; - } - /** * Creates a new {@link FeedbackEvent} and adds it to the queue * of events to be sent.