diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt index 575dd42..c2fff07 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/AndroidAutoBaseScreen.kt @@ -37,8 +37,8 @@ import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.GoogleMapOptions import com.google.android.libraries.navigation.NavigationViewForAuto - -open class AndroidAutoBaseScreen(carContext: CarContext) : Screen(carContext), SurfaceCallback, NavigationReadyListener { +open class AndroidAutoBaseScreen(carContext: CarContext) : + Screen(carContext), SurfaceCallback, NavigationReadyListener { private val VIRTUAL_DISPLAY_NAME = "AndroidAutoNavScreen" private var mVirtualDisplay: VirtualDisplay? = null private var mPresentation: Presentation? = null @@ -55,19 +55,25 @@ open class AndroidAutoBaseScreen(carContext: CarContext) : Screen(carContext), S private fun initializeNavigationListener() { GoogleMapsNavigationSessionManager.navigationReadyListener = this - mIsNavigationReady = GoogleMapsNavigationSessionManager.getInstance().isInitialized() + try { + mIsNavigationReady = GoogleMapsNavigationSessionManager.getInstance().isInitialized() + } catch (exception: RuntimeException) { + // If GoogleMapsNavigationSessionManager is not initialized navigation is not ready. + mIsNavigationReady = false + } } private fun initializeSurfaceCallback() { carContext.getCarService(AppManager::class.java).setSurfaceCallback(this) } - private val mLifeCycleObserver: LifecycleObserver = object : DefaultLifecycleObserver { - override fun onDestroy(owner: LifecycleOwner) { - GoogleMapsNavigationSessionManager.navigationReadyListener = null - mIsNavigationReady = false + private val mLifeCycleObserver: LifecycleObserver = + object : DefaultLifecycleObserver { + override fun onDestroy(owner: LifecycleOwner) { + GoogleMapsNavigationSessionManager.navigationReadyListener = null + mIsNavigationReady = false + } } - } private fun isSurfaceReady(surfaceContainer: SurfaceContainer): Boolean { return surfaceContainer.surface != null && @@ -163,7 +169,7 @@ open class AndroidAutoBaseScreen(carContext: CarContext) : Screen(carContext), S ) {} } - fun sendAutoScreenAvailabilityChangedEvent(isAvailable: Boolean) { + private fun sendAutoScreenAvailabilityChangedEvent(isAvailable: Boolean) { GoogleMapsNavigationPlugin.getInstance()?.autoViewEventApi?.onAutoScreenAvailabilityChanged( isAvailable ) {} diff --git a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationSessionManager.kt b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationSessionManager.kt index 9ad0953..f4e950f 100644 --- a/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationSessionManager.kt +++ b/android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationSessionManager.kt @@ -99,6 +99,7 @@ private constructor(private val navigationSessionEventApi: NavigationSessionEven return instance!! } } + private var navigator: Navigator? = null private var isNavigationSessionInitialized = false private var arrivalListener: Navigator.ArrivalListener? = null diff --git a/example/android/app/src/main/kotlin/com/google/maps/flutter/navigation_example/SampleAndroidAutoSession.kt b/example/android/app/src/main/kotlin/com/google/maps/flutter/navigation_example/SampleAndroidAutoSession.kt index af74406..bd64cdc 100644 --- a/example/android/app/src/main/kotlin/com/google/maps/flutter/navigation_example/SampleAndroidAutoSession.kt +++ b/example/android/app/src/main/kotlin/com/google/maps/flutter/navigation_example/SampleAndroidAutoSession.kt @@ -39,10 +39,6 @@ class SampleAndroidAutoSession(sessionInfo: SessionInfo): Session() { lifecycle.addObserver(object: DefaultLifecycleObserver { override fun onCreate(owner: LifecycleOwner) { Log.i(TAG, "In onCreate()") - } - - override fun onStart(owner: LifecycleOwner) { - Log.i(TAG, "In onStart()") carContext .bindService( Intent(carContext, SampleAndroidAutoService::class.java), @@ -51,6 +47,10 @@ class SampleAndroidAutoSession(sessionInfo: SessionInfo): Session() { ) } + override fun onStart(owner: LifecycleOwner) { + Log.i(TAG, "In onStart()") + } + override fun onResume(owner: LifecycleOwner) { Log.i(TAG, "In onResume()") } @@ -61,11 +61,11 @@ class SampleAndroidAutoSession(sessionInfo: SessionInfo): Session() { override fun onStop(owner: LifecycleOwner) { Log.i(TAG, "In onStop()") - carContext.unbindService(mServiceConnection) } override fun onDestroy(owner: LifecycleOwner) { Log.i(TAG, "In onDestroy()") + carContext.unbindService(mServiceConnection) } }) }