Problem :- I am making a Android Setting screen like view in my app. Tapping on item on left side list opens a fragment in right side. And right side fragment can go 2-3 level deep ie creating more fragments. If user randomly tap on menu items and go in and out on random screens, i found a large number of fragments are creating who get old one get garbage collected in 2-3 seconds of creation of new fragment.
Approach :- I chose a differ approach I decides to store them in pool. Technically speaking pool is a HashMap, see my pseudo Code Logic:-
if(Status.Found == serachInPoolMAP(Fragment1)) { return storedFragmentObject; } else { Fragment object = CreateAndStoreInMAP(Fragment1) ; return newStoredObject. }
Question :- By my approach Garbage collection was reduced completely but memory consumption got increased slightly . My question is what is better way to handle multiple fragments in a screen ? storing objects in pool or creating new heavy fragment object on every new user tap or there is something i am doing wrong.
Aucun commentaire:
Enregistrer un commentaire