0

Here is my code:

@Override
public void onSaveInstanceState(Bundle savedInstanceStateBundle)
{
    savedInstanceStateBundle.putInt(AVERAGE_SESSION_VALUE_HOLDER, averageSessionSeek.getProgress());
    savedInstanceStateBundle.putInt(CONFIDENCE_VALUE_HOLDER, confidenceSeek.getProgress());
    savedInstanceStateBundle.putInt(CONVERSION_TIME_VALUE_HOLDER, conersionTimeSeek.getProgress());

}

Above code is belongs to InputFragment.java which extends Fragment. The above methods saves the state of instances so when the user navigate away from that particular Fragment and come back to it, the instances are restored. I tried it with the below code

@Override 
public void onRestoreInstanceState(Bundle savedInstanceStateBundle)
{

}

But it fails, compile errors. So, how can I reload the instance states in Fragments?

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463

2 Answers2

0

Fragments don't have onRestoreInstanceState… it's onActivityCreated() (for technical reasons this was horribly implemented this way by the Android team).

See this thread on StackOverflow for more information.

Community
  • 1
  • 1
Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144
0

The docs for onSaveInstanceState say this:

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted. If a new instance of the fragment later needs to be created, the data you place in the Bundle here will be available in the Bundle given to onCreate(Bundle), onCreateView(LayoutInflater, ViewGroup, Bundle), and onActivityCreated(Bundle).

This corresponds to Activity.onSaveInstanceState(Bundle) and most of the discussion there applies here as well.

Instead of onSaveInstanceState(), use onActivityCreated(Bundle).

Community
  • 1
  • 1
Melquiades
  • 8,496
  • 1
  • 31
  • 46