Fixed
Status Update
Comments
la...@gmail.com <la...@gmail.com> #2
It is not possible for the view of the NavHostFragment to be available in the onCreate() of the Activity. In this case, the NavHostFragment lifecycle method follows the Activity lifecycle methods directly therefore, when the activity is on onCreate() so is the NavHostFragment. However, if the Fragment Lifecycle was driven with a LifecycleObserver (https://issuetracker.google.com/issues/127528777 ), onCreate() could be dispatched for a Fragment separately from the onCreate() for an Activity (or a parent Fragment if using a child Fragment). This means that if you were using a LifecycleObserver, it would be possible for the views to be available when onCreate() is dispatched and findNavController() would work in the LifecycleObserver's onCreate().
This is being tracked byhttps://issuetracker.google.com/issues/143145612 .
This is being tracked by
il...@google.com <il...@google.com> #3
Possible workaround #4: call findNavController in onPostCreate.
Description
Version used: androidx.fragment:fragment:1.2.0
Devices/Android versions reproduced on:
Calling FragmentManager toString() when it is not attached to an Activity crashes with NPE since mHost is null here:
@NonNull
@Override
public String toString() {
StringBuilder sb = new StringBuilder(128);
sb.append("FragmentManager{");
sb.append(Integer.toHexString(System.identityHashCode(this)));
sb.append(" in ");
if (mParent != null) {
Class<?> cls = mParent.getClass();
sb.append(cls.getSimpleName());
sb.append("{");
sb.append(Integer.toHexString(System.identityHashCode(mParent)));
sb.append("}");
} else {
Class<?> cls = mHost.getClass();
sb.append(cls.getSimpleName());
sb.append("{");
sb.append(Integer.toHexString(System.identityHashCode(mHost)));
sb.append("}");
}
sb.append("}}");
return sb.toString();
}
Originally detected with a dirty hack of dump()ing a Fragment to detect if it's in backstack or not, as in