What happens after replacing a fragment in a transaction

I want to know

getFragmentManager()
                .beginTransaction()
                .replace(
                        R.id.main,
                        Fragment.instantiate(LoadingScreen.this,
                                "com.myapp.fragments.fragment1",
                                bundle)).commit();

      

and then we will call

  getFragmentManager()
                    .beginTransaction()
                    .replace(
                            R.id.main,
                            Fragment.instantiate(LoadingScreen.this,
                                    "com.myapp.fragments.fragment2",
                                    bundle)).commit();

      

What happens to the Fragment1 view? Will it be automatically destroyed, do we need to manage garbage collection?

respectfully

+3


source to share


1 answer


As per Android developers note :



When you remove or replace a fragment and add a transaction to the back stack, the removed fragment is stopped (not destroyed). If the user goes back to restore the chunk, it will restart. If you don't add the transaction to the back stack, then the chunk is destroyed when removed or replaced.

+4


source







All Articles