1

Almost every source says to persist data in onPause() instead of onSaveInstanceState() in preparation for the activity being torn down/set up again.

However, I cannot seem to find a concrete example of saving data to the bundle inside of a fragment's onPause() method. (outState is not available during onPause() method. It is only available in onSaveInstanceState().)

What code do I add to persist my page data properly to its outState using

override fun onPause() {
    super.onPause()
    // ???
}
Alan Nelson
  • 1,129
  • 2
  • 11
  • 27
  • What sources are you looking at? The [Saving State with Fragments guide](https://developer.android.com/guide/fragments/saving-state#savedstate) does not mention that at all and very specifically points you to use `onSaveInstanceState()`. – ianhanniballake May 13 '21 at 19:29
  • This and others all say "...should save important information within the onPause-Method because the onsaveinstance-method is not part of the android lifecycle." https://stackoverflow.com/questions/151777/how-to-save-an-activity-state-using-save-instance-state – Alan Nelson May 13 '21 at 19:32
  • Please consider official resources just slightly more trustworthy than stack overflow questions from 8+ years ago. – ianhanniballake May 13 '21 at 19:36

0 Answers0