Android onsaveinstancestate not called. If they are by some circumstances not called, you might actually pass some information using method setArguments () and this information should preserve even if your app is in the background and you need to recreate the fragment again. onCreate (Bundle) was called first, but the bundle didn't have the key/values I set with onSaveInstanceState (Bundle). Nov 4, 2010 · In my case, onRestoreInstanceState was called when the activity was reconstructed after changing the device orientation. Dec 12, 2016 · In Activity B, when i click on a button, finish () is called, which in turn calls onDestroy () of Activity B and returns to activity A. If the Activity then actually gets killed by Android, the OS will make sure you receive a call to onRestoreInstanceState() as well passing the same bundle you used to save your activity's state in onSaveInstanceState() method. The relev. Most implementations will simply use onCreate (Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow Nov 9, 2014 · If your app goes to the background, onSaveInstanceState and onRestoreInstanceState are called so you can you them. The activity that contains the fragment has a portrait layout in /res/layout/, and an al Mar 28, 2014 · Steven Byle's answer (in that link) says: "The hack you added, directly calling onSaveInstanceState (new Bundle ()); inside of onPause, is a very bad practice, as you should never call the lifecycle callbacks directly. The relev Dec 12, 2016 · In Activity B, when i click on a button, finish () is called, which in turn calls onDestroy () of Activity B and returns to activity A. That state is lost on a screen rotation. According to android documentation, Before onDestroy is called, onSaveInstanceState (Bundle bundle) will be called, where i do the following. May 7, 2025 · I have a fragment which has its own state (selected buttons, etc). May 27, 2013 · Description : This method is called after onStart () when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. @Override public void onSaveInstanceState(Bundle outState) { Jan 29, 2015 · The method is only called if the Android OS anticipates that it may have to kill your activity to reclaim resources. May 28, 2018 · I created a custom view, and tried to restore the state automatically on screen rotation (just as EditText restores current input text automatically), but when I see the log, onSaveInstanceState is Jan 29, 2014 · I have seen a few similar questions about onSaveInstanceState not getting called for Fragments, but in my case Fragments work fine, it's the main FragmentActivity that's having trouble. Dec 30, 2013 · Similarly, several possibilities exist for onSaveInstanceState(). So when are they called exactly? Ideally, what I would like is to see a combined diagram showing the activity lifecycle states and the save/restore methods, if that exists.