Skip to content

Commit 90f5fb5

Browse files
fix: enable android turn by turn events on background (#613)
1 parent 322ebdc commit 90f5fb5

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

android/src/main/java/com/google/android/react/navsdk/NavModule.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import android.location.Location;
1818
import androidx.annotation.NonNull;
1919
import androidx.annotation.Nullable;
20-
import androidx.lifecycle.LifecycleOwner;
2120
import androidx.lifecycle.Observer;
2221
import com.facebook.react.bridge.Arguments;
2322
import com.facebook.react.bridge.LifecycleEventListener;
@@ -286,17 +285,15 @@ public void initializeNavigationSession(
286285
// Initialize the navigation API
287286
initializeNavigationApi();
288287

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.
290291
// Remove any existing observer first to prevent duplicates after cleanup+reinit cycles.
291292
UiThreadUtil.runOnUiThread(
292293
() -> {
293294
removeNavInfoObserver();
294295
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);
300297
});
301298
}
302299

@@ -354,6 +351,7 @@ private void onNavigationInitError(int errorCode) {
354351
}
355352
pendingInitPromise.reject(errorCodeStr, errorMessage);
356353
pendingInitPromise = null;
354+
UiThreadUtil.runOnUiThread(this::removeNavInfoObserver);
357355
}
358356
}
359357

@@ -1093,5 +1091,7 @@ public void onHostResume() {
10931091
public void onHostPause() {}
10941092

10951093
@Override
1096-
public void onHostDestroy() {}
1094+
public void onHostDestroy() {
1095+
UiThreadUtil.runOnUiThread(this::removeNavInfoObserver);
1096+
}
10971097
}

0 commit comments

Comments
 (0)