The only difference of retained instance in Fragment's lifecycle is that onCreate()
don't calls. But at this state View isn't inflated yet.
When must I call methods like loadNews()
of Presenter
of Fragment with setRetainInstance(true)
? I want to loadNews()
only when fresh instance of Fragment was created.
Do it in Fragment.onViewCreated()
because at this point you can be sure that the UI (View) is initialized and ready to display things (otherwise i.e. presenter calling view.showLoading() would result in a NullPointerException). But you have to ensure by your own that loadingData is only invoked the first time (i.e. check if bundle == null
)
If you use Mosby's ViewState Feature, then override onNewViewState()
method and call presenter.loadData()
. Mosby only ever calls this method on the first time the View appears, so you don't have to check if bundle == null
by your own.