Deprecate Fragment’s onActivityCreated() on Android

Bram Yeh
1 min readMar 26, 2020
  • Brief

In the further, Android will deprecated Fragment’s onActivityCreated. We should use onViewCreated() generally, but some initialization should be in onCreate(). Moreover, you can use LifeCycleObserver.

https://android-review.googlesource.com/c/platform/frameworks/support/+/1189651

Deprecate Fragment’s onActivityCreated The original purpose of the onActivityCreated() callback was to allow fragment logic to be tied to the creation of its activity. We should no longer be encouraging this coupling. We should promote passing in external dependencies as construction parameters using FragmentFactory. Code touching the fragment’s view should be done in onViewCreated() and other initialization code should be in onCreate(). To receive a callback specifically when the activity’s onCreate() is complete, a LifeCycleObserver should be registered on the activity’s Lifecycle in onAttach(), and removed once the onCreate() callback is received.

--

--