https://kotlinlang.org logo
#android
Title
# android
c

CamilleBC

09/13/2018, 3:25 PM
Hello ! If I create a fragment programmatically, should I add Observers on a view for some LiveData (in a ViewModel) in the
onCreateView
function, or somewhere else?
d

dgngulcan

09/13/2018, 3:34 PM
I'm initializing and observing everything inside
onActivityCreated
because it is called when the fragment's view hierarchy instantiated
c

CamilleBC

09/13/2018, 3:36 PM
Okay ! Thanks you very much 🙂
🙌 2
s

Sam

09/13/2018, 3:57 PM
Article was updated few months ago and recommendation is to use getViewLifecycleOwner() in onCreateView()
👍 2
c

CamilleBC

09/13/2018, 3:59 PM
@Sam Thanks for that article! I'll be sure to read it !
4 Views