Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 20. Activity fragments > Fragment back stack - Pg. 556

556 : ft.commit(); C HAPTER 20 Activity fragments You can then perform fragment operations such as the following: Add fragments: fragTransaction.add(, newFragment); Replace an existing fragment: fragTransaction.replace(, newFragment); Remove an existing fragment: fragTransaction.remove(newFragment); Add the fragment to the back stack: fragTransaction.addToBackStack(null); Or, you can call any of the other fragment operations mentioned earlier, as needed. Remember to commit the transaction by calling the FragmentTransaction.commit() method. All operations in a transaction are committed together. Similarly, operations in a transaction are reverted together when you press the Back key or simulate a back-stack pop. Committed transactions are scheduled for execution in the Activity 's main UI thread, but you can request an immediate execution of pending transactions by call- ing the FragmentTransaction . executePendingTransactions() method.