The issue is, we have like ~10 fragments which needs to be shown on basis of backend. whenever we switch the fragment from one to another we need the state of that fragment to be stored. The fragments contain not only complex view logic as well as business logic too.
For example : we have 3 fragments f1,f2,f3.
we switched from f1 -> f2 by pressing next button in f1 state of f1 is added to backstack
we again switch from f2 -> f3 by pressing next button in f2 state of f2 is added to backstack
now, when we want to go to f2 from f3 which is done by pressing previous button in f3. as state was kept track. The state was returned as it by poppingbackstack
now comping to issue, again we want to switch from f2 -> f3 and we need f3 state to be reserved as f3 was visited before , when we try to do this the fragment is recreating and all view & business logic & states are getting lost.
Things Tried :
- Tried saving states to local preferences, but ended up taking huge chunk of memory & cpu power for saving & retrieving data bundle as data was huge which included views & some business logic too
- We created a singleton pattern which would save the fragment as list and iterate b/w them but instead of restoring the state, the fragment was recreating and was also resource heavy.
- Tried view pager , disabled swipe-left/right functionality, state was reserved could not switch the fragments within fragments, need to add the new fragments at first which could not be done as we get the list of fragments to be shown in fragments like 2-3. nearly most of the codebase needs to be changed which may alter a bit stability & functionality of application behavior.