0

Okay I know this has been asked previously but just hear me out !

ISSUE

I want to save state of a fragment and then retrieve it in onCreateView method .

I have a ViewPager in my MainActivity with Four Fragments in it .

I have used viewpager.setOffscreenPageLimit(2) so fragments does not get recreated if am in any of two adjacent fragments but if i am in my first fragment and i go to fourth one then fragment first gets recreated .

and if save it in onSaveInstance inside fragment then that does not get called until host activity's same method is not called , which will not get called if am just swiping between fragments

Answer here also has same problem , it is saving fragments in host activity's onSaveInstance method .So i know how to save fragments state and retrieve it if my host activity gets recreated but what if only fragments gets recreated ?

So How can i save state of a fragment without depending on host activity and then retrieve it in onCreateView method of fragment ?

UPDATE Just realized how dumb a person can be , data was there all the time i was not just refilling the views with it .

Thanks in advance.

Community
  • 1
  • 1
Devansh Kumar
  • 1,552
  • 1
  • 15
  • 27
  • Fragment can't be recreated if activity not recreated in your case. – Divers Aug 25 '16 at 07:18
  • @Divers yes my mistake , it is not getting destroyed but onPause is getting called and after that same lifecycle is repeated , oncreate then oncreateview but the problem is that data in fragment which fill the view is getting null , so how do i save and retrieve that ? – Devansh Kumar Aug 25 '16 at 07:40
  • If only onPause() is called, no data would be lost. What exactly is being null? – Ruben Renzema Aug 25 '16 at 08:14
  • @RubenRenzema yeah ....i am stupid ...data is there i am just not reintegrating with views....sorrry to all for wasting your time – Devansh Kumar Aug 25 '16 at 08:26

0 Answers0