From 88b760bba81f73338334a1a9a13ac013ce91015e Mon Sep 17 00:00:00 2001 From: YoussefHenna Date: Mon, 9 Sep 2024 13:23:55 +0300 Subject: [PATCH] Android: Stop trip session when detached + don't start foreground service --- .../modules/mapboxnavigation/ExpoMapboxNavigationView.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/expo/modules/mapboxnavigation/ExpoMapboxNavigationView.kt b/android/src/main/java/expo/modules/mapboxnavigation/ExpoMapboxNavigationView.kt index f726d58..8c4af88 100644 --- a/android/src/main/java/expo/modules/mapboxnavigation/ExpoMapboxNavigationView.kt +++ b/android/src/main/java/expo/modules/mapboxnavigation/ExpoMapboxNavigationView.kt @@ -578,6 +578,9 @@ class ExpoMapboxNavigationView(context: Context, appContext: AppContext) : ExpoV mapboxNavigation?.unregisterVoiceInstructionsObserver(voiceInstructionsObserver) mapboxNavigation?.unregisterArrivalObserver(arrivalObserver) mapboxNavigation?.unregisterOffRouteObserver(offRouteObserver) + if(mapboxNavigation?.isDestroyed != true){ + mapboxNavigation?.stopTripSession() + } speechApi.cancel() voiceInstructionsPlayer.shutdown() mapView.location.removeOnIndicatorPositionChangedListener(onIndicatorPositionChangedListener) @@ -588,7 +591,7 @@ class ExpoMapboxNavigationView(context: Context, appContext: AppContext) : ExpoV private fun onRoutesReady(routes: List){ mapboxNavigation?.setNavigationRoutes(routes) - mapboxNavigation?.startTripSession() + mapboxNavigation?.startTripSession(withForegroundService=false) navigationCamera.requestNavigationCameraToFollowing( stateTransitionOptions = NavigationCameraTransitionOptions.Builder() .maxDuration(0) // instant transition