Skip to content

Commit f166f2a

Browse files
Delay navigation until activity is resumed
1 parent 28afd9b commit f166f2a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/main/MainActivity.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ private void navigateToPreferredDestination(int preferredDestination) {
327327
lastPreferredStartDestination = preferredDestination;
328328
return;
329329
}
330+
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) {
331+
getLifecycle().addObserver(new DefaultLifecycleObserver() {
332+
@Override
333+
public void onResume(@NonNull LifecycleOwner owner) {
334+
getLifecycle().removeObserver(this);
335+
navigateToPreferredDestination(preferredDestination);
336+
}
337+
});
338+
return;
339+
}
330340
NavOptions options = new NavOptions.Builder()
331341
.setPopUpTo(graph.getStartDestinationId(), true)
332342
.setLaunchSingleTop(true)

0 commit comments

Comments
 (0)