I would like to understand the main differences. And in what cases to use this or that?
- oneJudging by the name, the first one is called before the View is created, and the second after - Anton Shchyrov
1 answer
OnCreateView is called when the View and the layout itself is injected in it
OnViewCreated is called after the layout initialized.
What and when to use? OnCreateView - here we just create a layout
OnViewCreated - here we already bind logic to the views. This ensures that the view is created, and no null pointer will fall.
In fact, you can do without OnViewCreated , and do everything in OnCreateView
So here is the number of logic of separation of duties for methods.
The real situation is when I use OnViewCreated - I use Butterknife and in the base snippet I implemented OnCreateView where I call Butternife.bind(this,view) And all the heirs' logic is already in OnViewCreated . And so I would have to call OnCreateView.super() every time and in the case of multiple inheritance there could be collisions and everything like that