Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event when the FragmentTransaction is completed

Is it possible to have an event when the FragmentTransaction is completed ?

FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, fragment).commit(); 

In fact, I use a Drawer for my application and I would like to trigger invalidateOptionsMenu(); when the transaction is completed to change the menu of my action bar.

like image 848
lopez.mikhael Avatar asked Nov 01 '13 09:11

lopez.mikhael


People also ask

How do you know if a fragment is destroyed?

Since all fragments are destroyed if the activity is destroyed, a simple answer could be calling getActivity(). isDestroyed() returning true if the activity is destroyed, therefore the fragment is destroyed.

What is the process of starting a new fragment?

Step 1: Create a New Project To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Step 2: Right-click on the First button inside java, then click on New. Step 2: Then Go to Fragment. Step 3: (The next step is to choose the Fragment type.

What is the use of FragmentManager in Android?

FragmentManager is the class responsible for performing actions on your app's fragments, such as adding, removing, or replacing them, and adding them to the back stack.

What will happen if an activity with a retained fragment is rotated?

Fragments — Scenario 3: Activity with retained Fragment is rotated. The fragment is not destroyed nor created after the rotation because the same fragment instance is used after the activity is recreated. The state bundle is still available in onActivityCreated .


1 Answers

You don't need to wait for the fragment transaction to complete, You can call

getSupportFragmentManager().executePendingTransactions(); 

after your commit() function call.

This will ensure that the transaction is complete.

like image 142
Eldhose M Babu Avatar answered Oct 08 '22 12:10

Eldhose M Babu