I need to know why do we always instantiate a new object of fragment using either A.newInstance() or A() if we know there is already an instance exists. Does it not increase memory uses by the app in Android?
In my case I have an activity and multiple fragments which are opened by menus present in drawer fragment. These fragments further might open other fragments which are not listed in drawer menu. So I am wondering if is it normal to create new instances of secondary fragments by top fragment each time. The same is true for top level fragments. My flow is explained below:
- Fragment A (new instance first time)
- Fragment B (lower level fragment/new instance, instantiated by A)
- Back to A (by pressing up arrow)
- Fragment B (lower level fragment/again new instance, instantiated by A)
- Back to A (by pressing up arrow)
- Fragment X (new instance first time/top level fragment/from drawer menu)
- Fragment A (again new instance of A/top level fragment/from drawer menu)
Is it correct to have multiple instances of fragments A (top level / point 7) and B (lower level / point 4)? As I am using this strategy?