I faced with that problem when I started to use ViewPager
. As every page is nested Fragment
, I can't call setRetainInstance(true)
for it. So, I need to store Fragment
's state to a Bundle
and cancel/recall remote API methods onViewAttached/Detached
which I don't want to.
What I learn about this situation:
RecyclerViewPager
to avoid using nested Fragments
, but I still can't keep an instance of Presenter
. One of the ways is to use a static field, but the same thing can I do with the Fragment
.rootViewPager
under MainActivity and use it in Fragments
via setVisibility(GONE/VISIBLE)
and replacing Adapter
. So, every Fragment
placed into this ViewPager
will not have parent Fragment
and I will solve my case. Suitable and elegant, but not the best solution as I think.Any other variants?
In Mosby 3.0 Presenters can be retained even without setRetainInstance(true)
... I would suggest to wait until 3.0 release ...
So, I need to store Fragment's state to a Bundle and cancel/recall remote API methods onViewAttached/Detached which I don't want to.
Mosby 2.0 does exactly that for you but you have to make your ViewState and your data implement Parcelable. In that case the presenter instance won't survive screen orientation changes, but presenter will "resume" on the same state / point (a new presenter instance will be created, async tasks etc. might be restarted too). See RestorableViewState (javadoc is slightly outdated, because it mentions that this is the only way to work with activities which since Mosby 2.0 is not true anymore)