I have seen a few similar questions about onSaveInstanceState
not getting called for Fragment
s, but in my case Fragment
s work fine, it's the main FragmentActivity
that's having trouble.
The relevant code looks fairly simple:
public class MyFActivity extends FragmentActivity implements ActionBar.TabListener {
String[] allValues; // data to save
@Override
protected void onSaveInstanceState (Bundle outState) {
Log.d("putting it!", allValues.toString());
outState.putStringArray("allValues", allValues);
super.onSaveInstanceState(outState);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
allValues = savedInstanceState.getStringArray("allValues");
Log.d("getting it!", allValues.toString());
}
}
}
When pausing the activity (using the back button), the onSaveInstanceState
is never called, and consequently, savedInstanceState
is always null
within the onCreate
method upon resuming the app. I tried adding a block like this:
@Override
public void onPause() {
super.onPause();
onSaveInstanceState(new Bundle());
}
which was suggested in https://mcmap.net/q/168194/-fragment-39-s-onsaveinstancestate-is-never-called but while onSaveInstanceState
then gets called, savedInstanceState
remains null
within onCreate
method. What am I missing?
savedInstanceState
is lost. Do you see the appropriatesaveInstanceState
inonCreate()
when you rotate the device? – Rabid