0

I'm new to android, I have a fragment and it goes through onPause, destroyView, destroy, but onSaveInstanceState is never called.

Is is this expected?

How can I save the state?

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putParcelable(KEY_CATEGORY, category);
    super.onSaveInstanceState(outState);
}
serenskye
  • 3,467
  • 5
  • 35
  • 51

1 Answers1

0

The system calls onSaveInstanceState when it is about to remove your fragment from the memory/recreate it for any reason. It won't be called otherwise.

If this is your case and onSaveInstanceState is still not called, a code snippet of your fragment might help.

This happens many times due to omitting the line of calling this method of the superclass. Like here, for example. Make sure you call it.

Community
  • 1
  • 1
Jong
  • 9,045
  • 3
  • 34
  • 66
  • super is definitely being called. I think maybe the problem is that the fragment manager is never reusing that fragment because the containing view is removed – serenskye Nov 07 '12 at 16:42