Hey guys. In the following design, I have a BottomAppBar with 4 icons.
Each icon, cause the screen to show a different Fragment, totalling 4 different Fragments (some screens have sub fragments in them).
Currently, I created a variable "currentlySelectedFragment".
Whenever an Icon is selected, that variable is changed causing the FragmentManager to replace the previously selected Fragment (thus killing it too)
Do you think, that I should keep all of the 4 Fragments alive? as i perform replace, the next time I open that Fragment I need to do loading again.
I wonder what is the best practice regarding Fragments here.
Because on one side, I need to load the UI again everytime, on the other side I don't want to use too much memory.
i
Ianmedeiros
04/02/2020, 1:45 AM
Well. I think there are no universal answers for this.
Ianmedeiros
04/02/2020, 1:46 AM
It needs to be evaluated on a case by case basis:
Does your fragments really consumes too much memory? Does the “data-loading” really takes too much processing time?
Ianmedeiros
04/02/2020, 1:47 AM
You can scope some data to the activity, some to the fragment…
Ianmedeiros
04/02/2020, 1:47 AM
You can store just minimal information to accelerate the re-loading..