In the following Android lifecycle method:
@Override
public View onCreateView(
LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
...
return view;
}
onCreateView takes in a LayoutInflater, @Nullable Viewgroup, and a @Nullable Bundle.
The issue I have is in the sample program I am referring to: sceneform-android-sdk
There doesn't seem to be an instance where we call the method onCreateView and pass in a LayoutInflatter, Viewgroup, and Bundle. And yet, we are able to use the passed in parameters.
Yes we call super.onCreateView(...), but again, where did the values passed as arguments to the super, that were the parameters of our local version of onCreateView, come from?
My main question, reiterated, would be what is it that calls the onCreateView method and passes in the parameters?
My second question is, if I were to create a method in the same activity onCreateView is in:
public void foo(LayoutInflater myInflater) // Or it takes in a Bundle, Viewgroup, etc.
Would my foo method also get the same parameter values as the onCreateView method?
Lastly, my third question would be in a similar vein. A view is returned, but like before, it doesn't look like we handle the return. So, what handles the return value??
If possible, I would humbly request further reading regarding how Android core code works so as to implement my own methods that properly make use of
parameters from Android and how to properly return values to Android as well.
The documentation for
Fragment.onCreateView()indicates the following:The Android framwork makes all lifecycle calls itself.The Android framework will call
onCreate()on the fragmentto initialize the fragment. At some later time, the Android framework will callonCreateView()` on the fragment. The following parameters are passed:LayoutInflater: TheLayoutInflaterobject that can be used to inflate any views in theFragment. The framework gets theLayoutInflaterfrom theActivity'sContext.ViewGroup: If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate theLayoutParamsof the view. This parameter is the containerViewthat holds theFragment.Bundle: If non-null, this fragment is being re-constructed from a previous saved state as given here. In this case, theBundlecontains the most recently saved state of theFragment(ie: the data from the most recent call made to theFragmentsonSaveInstanceState()method).Regarding your other questions:
If you define a method
foo(), the Android framework would never call it. The Android framework has a specific set of defined methods that it calls on certain components (Activity, Service, BroadcastReceiver, Fragment, etc.) at specific times.The
Viewreturned fromonCreateView()will be used by the Android framework. The documentation clearly indicates how the returnedViewobject is used: