Why does the book set FragmentResultListener in onCreateView() instead of onCreate()?

Hi everyone,

I noticed that in the example code, setFragmentResultListener is called inside onCreateView().

From my understanding of the Fragment Result API, its usually recommended to attach the listener in onCreate() of the receiving fragment, so that the listener is ready as early as possible in the lifecycle. If it’s only set up in onCreateView(), there’s a chance that the result could be sent before the listener is attached (for example, if the sending fragment posts the result quickly).

Could someone explain the reasoning behind placing it in onCreateView() instead of onCreate()? Is this just for simplicity in the example code, or is there a particular advantage in doing it that way?

Thanks!