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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Bram Yeh
Bram Yeh

Written by Bram Yeh

Lead Android & iOS Mobile Engineer at Yahoo (Verizon Media) Taiwan https://www.linkedin.com/in/hanruyeh/

No responses yet

Write a response