I am using SlidingMenu
to open both right and left menu. It all works fine, except that I cannot find a way to preserve fragments' state after the app hasn't been used for at least few (~6) hours.
This is how I setup fragment in one of my menus:
if (savedInstanceState != null)
mContent = getSupportFragmentManager().getFragment(
savedInstanceState, "mContent");
if (mContent == null)
mContent = new SomeFragment();
setContentView(R.layout.content_frame);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_frame, mContent).commit();
When the user comes back to the app after a longer period of time, some of the fragments (either fragment with the left or with the right menu) become gray and even though I am aware of it and I try the following solution (example for the left menu):
mLeftMenuFragment = new LeftMenuFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.sliding_menu_left_content_frame,
mLeftMenuFragment).commit();
it doesn't help.
Note that I have also tried the commitAllowingStateLoss()
method (instead of commit()
) but it didn't help either.
I'm not sure but I think It would be better save state data in SharredPreferences or somewhere else and then recreate by hand. I think save Instance State better use for fast going back and forward or rotation and so on. Who knows what can happens in 6 hourse. Android can clean memor y or something else. You not controll it. It's my opinion.
My guess is that the problem is not with a fragment, but with the content inside of it. Do you have an adapter for the content of your menu? Check it (maybe post the code of your fragment and corresponding view/adapter), it seems that after you reinflate a fragment it shows the same invalid view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With