Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
As a workaround, you can call getChildFragmentManager() in onCreate() to initialize the child FragmentManager before adding your OnBackPressedCallback.
ap...@google.com <ap...@google.com> #3
Project: platform/frameworks/support
Branch: androidx-master-dev
commit 31b0014ed07038533faad8dbdefe871c91cf70bf
Author: Ian Lake <ilake@google.com>
Date: Thu Apr 25 14:54:33 2019
Eagerly construct the childFragmentManager
As we do work (setting up an OnBackPressedCallback)
in attachController(), it is important that we
construct the childFragmentManager eagerly to ensure
the proper ordering of callbacks.
Test: tests pass, new OnBackPressedCallbackTest passes
Fixes: 133175997
Change-Id: I7a9fa59ed693ab7f07b7f9bb506c52a5c579a452
M fragment/src/androidTest/java/androidx/fragment/app/OnBackPressedCallbackTest.kt
M fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
M fragment/src/main/java/androidx/fragment/app/FragmentManagerImpl.java
M navigation/fragment/src/main/java/androidx/navigation/fragment/NavHostFragment.java
https://android-review.googlesource.com/966056
https://goto.google.com/android-sha1/31b0014ed07038533faad8dbdefe871c91cf70bf
Branch: androidx-master-dev
commit 31b0014ed07038533faad8dbdefe871c91cf70bf
Author: Ian Lake <ilake@google.com>
Date: Thu Apr 25 14:54:33 2019
Eagerly construct the childFragmentManager
As we do work (setting up an OnBackPressedCallback)
in attachController(), it is important that we
construct the childFragmentManager eagerly to ensure
the proper ordering of callbacks.
Test: tests pass, new OnBackPressedCallbackTest passes
Fixes: 133175997
Change-Id: I7a9fa59ed693ab7f07b7f9bb506c52a5c579a452
M fragment/src/androidTest/java/androidx/fragment/app/OnBackPressedCallbackTest.kt
M fragment/src/main/java/androidx/fragment/app/Fragment.java
M fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
M fragment/src/main/java/androidx/fragment/app/FragmentManagerImpl.java
M navigation/fragment/src/main/java/androidx/navigation/fragment/NavHostFragment.java
il...@google.com <il...@google.com> #4
We've fixed this internally and it'll be available in the next version of Fragments.
Description
Version used: 1.1.0-alpha09
Not sure why you're doing this, but there's a back pressed listener being added to the dispatcher in the initializeChildFragmentManager method, which itself is only called in performOnCreateView. Why isn't the child fragment manager just instantiated when the fragment is first initialized? There are so many bugs around this. Anyway, this means any back pressed listener added in the Fragment's onCreate is essentially pointless since it will always be overridden by the fragment manager's one which pops the back stack. However, back pressed listeners added in onViewCreated work since they're after the FM's listener.