I'm using Fragments in my app where all of them share one base activity, so activity is not destroyed till app closes. When I navigate from one fragment to another, I have used the following code:
Fragment myFragment=new MyFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().addToBackStack("MyFragment")
.replace(R.id.content_frame, myFragment,"AirtimeFragment").commit();
When using it I have to create a new Object
for each fragment which is not good for memory consumption.
So I want to create one global method which manages all fragment in which it checks whether the fragment already exists, then no need to recreate it just uses the existing fragment object, so I can reduce memory consumption?