0

I have a fragment which shows system state like battery, wifi or other things like that and I have it at the top of Activities.

It's possible to save state between activities instead of initialize it when activities are created?

Something like save fragment when activity is closed and restore when next activity is created. Basically having same fragment instance along all activities.

I have read that it's possible to save state via FragmentManager in the application context but I don't find so much information about it. Do you have an example of that?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JuanDYB
  • 590
  • 3
  • 9
  • 23
  • Singleton object did not help you? – ysfcyln Oct 20 '20 at 20:52
  • Making Fragment Singleton? As I have readed the Android framework needs to have empty contructor – JuanDYB Oct 21 '20 at 08:40
  • Nope, I mean, create a singleton data holder class for necessary data and use this class everywhere, so you do not have to think about fragment state – ysfcyln Oct 21 '20 at 14:15
  • I have done this. The thing is that I wanted to make the activity load faster. At the moment I have this common fragment to all activities added to the activities in the layout XML and I think this is causing some delay in loading activity because before the activity load it have to load fragment. Maybe it's better to add fragments by code ... Thanks – JuanDYB Oct 21 '20 at 22:02

0 Answers0