Skip to content

Commit fa71176

Browse files
fix: android unregisterListeners crash on app disposal (#283)
1 parent e406ff6 commit fa71176

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

android/src/main/kotlin/com/google/maps/flutter/navigation/GoogleMapsNavigationSessionManager.kt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,30 +291,34 @@ private constructor(private val navigationSessionEventApi: NavigationSessionEven
291291
}
292292

293293
private fun unregisterListeners() {
294-
val navigator = getNavigator()
295-
if (remainingTimeOrDistanceChangedListener != null) {
296-
navigator.removeRemainingTimeOrDistanceChangedListener(remainingTimeOrDistanceChangedListener)
297-
remainingTimeOrDistanceChangedListener = null
298-
}
299-
if (arrivalListener != null) {
300-
navigator.removeArrivalListener(arrivalListener)
301-
arrivalListener = null
302-
}
303-
if (routeChangedListener != null) {
304-
navigator.removeRouteChangedListener(routeChangedListener)
305-
routeChangedListener = null
306-
}
307-
if (reroutingListener != null) {
308-
navigator.removeReroutingListener(reroutingListener)
309-
reroutingListener = null
310-
}
311-
if (trafficUpdatedListener != null) {
312-
navigator.removeTrafficUpdatedListener(trafficUpdatedListener)
313-
trafficUpdatedListener = null
314-
}
315-
if (speedingListener != null) {
316-
navigator.setSpeedingListener(null)
317-
speedingListener = null
294+
if (isInitialized()) {
295+
val navigator = getNavigator()
296+
if (remainingTimeOrDistanceChangedListener != null) {
297+
navigator.removeRemainingTimeOrDistanceChangedListener(
298+
remainingTimeOrDistanceChangedListener
299+
)
300+
remainingTimeOrDistanceChangedListener = null
301+
}
302+
if (arrivalListener != null) {
303+
navigator.removeArrivalListener(arrivalListener)
304+
arrivalListener = null
305+
}
306+
if (routeChangedListener != null) {
307+
navigator.removeRouteChangedListener(routeChangedListener)
308+
routeChangedListener = null
309+
}
310+
if (reroutingListener != null) {
311+
navigator.removeReroutingListener(reroutingListener)
312+
reroutingListener = null
313+
}
314+
if (trafficUpdatedListener != null) {
315+
navigator.removeTrafficUpdatedListener(trafficUpdatedListener)
316+
trafficUpdatedListener = null
317+
}
318+
if (speedingListener != null) {
319+
navigator.setSpeedingListener(null)
320+
speedingListener = null
321+
}
318322
}
319323
if (roadSnappedLocationListener != null) {
320324
disableRoadSnappedLocationUpdates()

ios/google_navigation_flutter/Sources/google_navigation_flutter/messages.g.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ protocol NavigationViewCreationApi {
18141814
}
18151815

18161816
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
1817-
class NavigationViewCreationApiSetup {
1817+
enum NavigationViewCreationApiSetup {
18181818
/// The codec used by NavigationViewCreationApi.
18191819
static var codec: FlutterStandardMessageCodec { NavigationViewCreationApiCodec.shared }
18201820
/// Sets up an instance of `NavigationViewCreationApi` to handle messages through the
@@ -2079,7 +2079,7 @@ protocol MapViewApi {
20792079
}
20802080

20812081
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
2082-
class MapViewApiSetup {
2082+
enum MapViewApiSetup {
20832083
/// The codec used by MapViewApi.
20842084
static var codec: FlutterStandardMessageCodec { MapViewApiCodec.shared }
20852085
/// Sets up an instance of `MapViewApi` to handle messages through the `binaryMessenger`.
@@ -4027,7 +4027,7 @@ protocol ImageRegistryApi {
40274027
}
40284028

40294029
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
4030-
class ImageRegistryApiSetup {
4030+
enum ImageRegistryApiSetup {
40314031
/// The codec used by ImageRegistryApi.
40324032
static var codec: FlutterStandardMessageCodec { ImageRegistryApiCodec.shared }
40334033
/// Sets up an instance of `ImageRegistryApi` to handle messages through the `binaryMessenger`.
@@ -4678,7 +4678,7 @@ protocol NavigationSessionApi {
46784678
}
46794679

46804680
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
4681-
class NavigationSessionApiSetup {
4681+
enum NavigationSessionApiSetup {
46824682
/// The codec used by NavigationSessionApi.
46834683
static var codec: FlutterStandardMessageCodec { NavigationSessionApiCodec.shared }
46844684
/// Sets up an instance of `NavigationSessionApi` to handle messages through the
@@ -5917,7 +5917,7 @@ protocol AutoMapViewApi {
59175917
}
59185918

59195919
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
5920-
class AutoMapViewApiSetup {
5920+
enum AutoMapViewApiSetup {
59215921
/// The codec used by AutoMapViewApi.
59225922
static var codec: FlutterStandardMessageCodec { AutoMapViewApiCodec.shared }
59235923
/// Sets up an instance of `AutoMapViewApi` to handle messages through the `binaryMessenger`.
@@ -7645,7 +7645,7 @@ protocol NavigationInspector {
76457645
}
76467646

76477647
/// Generated setup class from Pigeon to handle messages through the `binaryMessenger`.
7648-
class NavigationInspectorSetup {
7648+
enum NavigationInspectorSetup {
76497649
/// The codec used by NavigationInspector.
76507650
/// Sets up an instance of `NavigationInspector` to handle messages through the `binaryMessenger`.
76517651
static func setUp(binaryMessenger: FlutterBinaryMessenger, api: NavigationInspector?) {

0 commit comments

Comments
 (0)