|
17 | 17 | import android.location.Location; |
18 | 18 | import androidx.annotation.NonNull; |
19 | 19 | import androidx.annotation.Nullable; |
20 | | -import androidx.lifecycle.LifecycleOwner; |
21 | 20 | import androidx.lifecycle.Observer; |
22 | 21 | import com.facebook.react.bridge.Arguments; |
23 | 22 | import com.facebook.react.bridge.LifecycleEventListener; |
@@ -286,17 +285,15 @@ public void initializeNavigationSession( |
286 | 285 | // Initialize the navigation API |
287 | 286 | initializeNavigationApi(); |
288 | 287 |
|
289 | | - // Observe live data for nav info updates. |
| 288 | + // Observe nav info independently from the current Activity lifecycle. |
| 289 | + // Background turn-by-turn updates continue to arrive in NavInfoReceivingService even when the |
| 290 | + // app is paused, so using an Activity-bound LiveData observer drops them while backgrounded. |
290 | 291 | // Remove any existing observer first to prevent duplicates after cleanup+reinit cycles. |
291 | 292 | UiThreadUtil.runOnUiThread( |
292 | 293 | () -> { |
293 | 294 | removeNavInfoObserver(); |
294 | 295 | mNavInfoObserver = this::showNavInfo; |
295 | | - final Activity currentActivity = getReactApplicationContext().getCurrentActivity(); |
296 | | - if (currentActivity != null) { |
297 | | - NavInfoReceivingService.getNavInfoLiveData() |
298 | | - .observe((LifecycleOwner) currentActivity, mNavInfoObserver); |
299 | | - } |
| 296 | + NavInfoReceivingService.getNavInfoLiveData().observeForever(mNavInfoObserver); |
300 | 297 | }); |
301 | 298 | } |
302 | 299 |
|
@@ -354,6 +351,7 @@ private void onNavigationInitError(int errorCode) { |
354 | 351 | } |
355 | 352 | pendingInitPromise.reject(errorCodeStr, errorMessage); |
356 | 353 | pendingInitPromise = null; |
| 354 | + UiThreadUtil.runOnUiThread(this::removeNavInfoObserver); |
357 | 355 | } |
358 | 356 | } |
359 | 357 |
|
@@ -1093,5 +1091,7 @@ public void onHostResume() { |
1093 | 1091 | public void onHostPause() {} |
1094 | 1092 |
|
1095 | 1093 | @Override |
1096 | | - public void onHostDestroy() {} |
| 1094 | + public void onHostDestroy() { |
| 1095 | + UiThreadUtil.runOnUiThread(this::removeNavInfoObserver); |
| 1096 | + } |
1097 | 1097 | } |
0 commit comments