Is onActivityCreated() called after onViewCreated() in a Fragment?

After some further research I think I found the answer.

onActivityCreated added in version 22.1.0 void onActivityCreated (Bundle savedInstanceState)

Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state. It is also useful for fragments that use setRetainInstance(boolean) to retain their instance, as this callback tells the fragment when it is fully associated with the new activity instance. This is called after onCreateView(LayoutInflater, ViewGroup, Bundle) and before onViewStateRestored(Bundle).

Based on the documentation:

..fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place..

The view hierarchy should be fully instantiated and therefore onActivityCreated will be called after the completion of onViewCreated

UPDATE

Info: onActivityCreated is now deprecated

use onViewCreated(View, Bundle) for code touching the Fragment's view and onCreate(Bundle) for other initialization. To get a callback specifically when a Fragment activity's Activity.onCreate(Bundle) is called, register a androidx.lifecycle.LifecycleObserver on the Activity's Lifecycle in onAttach(Context), removing it when it receives the Lifecycle.State.CREATED callback.


Yes, it is for certain, as you found out. Also, see this answer for a cute little lifecycle drawing (the second one).