1

I have an app that only has 1 activity but have 4 fragments. For example,

My 1st fragment has a button, if I press the button, the textview's text will change to "test1" and when i go to the 2nd fragment, then go back to 1st fragment, the textview in the 1st fragment gets back to it's default value which is "New Text". But I already pressed the button so that the textview's text will change to "test1" right? How do I save a fragment's state like how I left it? For whoever will answer this, can you please give a sample code and explain it so it will make sense to me. Thank you and I hope I will learn something.

  • The basic idea is described [in these answers](http://stackoverflow.com/questions/15313598/once-for-all-how-to-correctly-save-instance-state-of-fragments-in-back-stack) and you can probably find more elaborate code examples if you search for `onSaveInstanceState()`. – Markus Kauppinen Nov 09 '16 at 17:03

0 Answers0