To manage fragment in an activity, you need to use the fragmentmanager object. You can obtain this object by calling the getfragmentmanager () method in the activity.
The fragmentmanager object can do the following:
1. Get the existing fragment in the activity, use findfragmentbyid () to obtain the fragment provided by the UI in the activity layout, or use the findfragmentbytag () method to obtain the fragment not provided by the UI;
2. Use the popbackstack () method to pop up the fragment from the rollback stack, similar to the user's rollback command;
3. Use addonbackstackchangedlistener () to register a listener for the rollback stack change.
For more information about these methods, refer to the fragmentmanager Class documentation.
As described in the previous chapter, you can also use fragmentmanager to open a fragmenttransaction object to execute transactions such as adding and deleting fragment.