Android FragmentManager
A FragmentManager
manages Fragments
in Android, specifically it handles transactions between fragments. A transaction is a way to add, replace, or remove fragments.
Android FragmentTransaction
As said before a FragmentTransaction
gives us methods to add, replace, or remove fragments in Android. It gives us an interface for interacting with fragments.
fragmentTransaction.replace(R.id.fragment_container, mFeedFragment);
The method replace(int containerViewId, Fragment fragment)
replaces an existing Fragment
object from the container containerViewId
and adds the the Fragment fragment
fragmentTransaction.addToBackStack(null);
This method, addToBackOfStack(String name)
, adds this transaction to the back stack, this can be used so that Fragments
are remembered and can be used again by the Activity
fragmentTransaction.commit();
The method commit()
schedules this transaction, this is not instantaneous; It is scheduled on the main thread to be done when the thread is ready.
Reference