I'm struggling with an issue regards Activity > ViewPager > Fragments
that are being totally destroyed and recreated again, i'm handling this kind of scenario like when the screen orientation
changed i just restore
my data
from the saved instance
, however when my device go idle for awhile and screen goes off
and ON
again, the saved data
inside the instance
is being destroyed
and its null.
code example:
Base Fragment
@Override public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Icepick.saveInstanceState(this, outState);
}
@Override public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Icepick.restoreInstanceState(this, savedInstanceState);
setRetainInstance(true);
}
Activity
mAdapter = new BrochureContentAdapter(getSupportFragmentManager(), models);
pager.setAdapter(mAdapter);
pager.setCurrentItem(position, true);
pager.setOffscreenPageLimit(models.size());
the BaseFragment
handle saving and restoring instance
via IcePick
when the screen rotates (recreated) everything goes well, my only issue is that within the fragment
that extends the BaseFragment
if the screen go idle
for awhile and ON
back, the saved instances are being totally destroyed.
anyone had similar issue before and find a way of tackling it?