Android class reference --- FragmentManager

Source: Internet
Author: User

1. inheritance relationship

Java. lang. Object

|____ Android. app. FragmentManager

2. class overview

This class provides interfaces for interacting with Fragment objects in the Activity.

Although FragmentManager APIs are introduced in the HONEYCOMB version, there is also an API version used by the FragmentActivity class on the old platform.

HONEYCOMB: http://developer.android.com/reference/android/ OS /Build.VERSION_CODES.html#HONEYCOMB

3. Class description

Nested (internal) Class

Interface FragmentManager. BackStackEntry

Represents a project entity of the Fragment rollback stack. This project entity is created when the FragmentTransaction. addToBackStack () method is called.

Interface FragmentManager. OnBackStackChangedListener

Interface for viewing stack rollback changes

Constant

Public static final int POP_BACK_STACK_INCLUSIVE

Tags set for popBackStack (String, int) and popBackStack (int, int) methods. If the tag is set when the two methods are called and the name or ID of the project entity in the rollback stack is provided, all matching project entities in the stack will be consumed, until there is no matching, or until it reaches the bottom of the stack.

Constant Value: 1 (0x00000001)

Public Constructor

FragmentManager ()

Public Method

Public abstract void addOnBackStackChanageListener (FragmentManager. OnBackStackChangedListener)

Add a new listener to listen for changes in the Fragment rollback stack.

Public abstract FragmentTransaction beginTransaction ()

Start a series of Edit operations related to Fragment objects associated with FragmentManager.

Note: A Fragment transaction can only be created/committed when the Activity saves its status. If the transaction is committed after the Activity. onSaveInstanceState () method is called, an error occurs. This is because the system framework needs to save the state of the current Fragment object, and if the Fragment is changed after the state is saved, the results of the change will also be lost.

Public abstract void dump (String prefix, FileDescriptor fd, PrintWriter writer, String [] args)

Prints the FragmentManager status to the specified stream.

Parameters:

Prefix ---> Print the output text before each line of text.

Fd ---> description of the stored file to be output.

Writer ---> specifies a PrintWriter object for the transfer operation.

Args ---> provides a set of additional parameters for the transfer request.

Public static void enableDebugLogging (boolean enabled)

Determines whether to enable the debug log of the Fragment manager in the framework ). If debug logs are enabled, the logs of Fragment operations performed by the Framework are displayed in Logcat.

Public abstract boolean executePendingTransactions ()

After the FragmentTransaction object is submitted using the FragmentTransaction. commit () method, it is executed asynchronously in the main thread of the process. If you want to immediately execute the operation in the waiting state, you must call this method (which can only be called in the main thread ). It should be noted that all the reconciliation-related behaviors will be executed in this call, so you should carefully confirm the call location of this method.

Returned value: If a pending transaction is executed, true is returned.

Public abstract Fragment findFragmentById (int id)

This method is used to find the Fragment object identified by the given id. This id can be the XML generated when the layout is filled or the container ID when the transaction is added. This method first searches for the Fragment object added to the currently managed Activity. If not found, it searches for all Fragment objects in the current rollback stack, to find the Fragment object that matches this ID.

Returned value: if it is found, a Fragment object is returned. Otherwise, null is returned.

Public abstract Fragment findFragmentByTag (String tag)

This method is used to find a Fragment object identified by a given label. This label can be derived from XML during layout filling or provided when adding transactions. This method first searches for the Fragment object added to the currently managed Activity. If not found, it searches for all Fragment objects in the current rollback stack, to find the Fragment object that matches this tag.

Returned value: if it is found, a Fragment object is returned. Otherwise, null is returned.

Public abstract FragmentManager. BackStackEntry getBackStackEntryAt (int index)

This method returns the BackStackEntry object identified by the index in the rollback stack. index 0 points to the entity object at the bottom of the stack.

Public abstract int getBackStackEntryCount ()

Returns the number of current object objects in the rollback stack.

Public abstract Fragment getFragment (Bundle bundle, String key)

Returns the Fragment object instance that was last placed using the putFragment (Bundle, String, Fragment) method.

Parameters:

Bundle ---> specifies the Bundle object from which to obtain the Fragment reference.

Key ---> specifies the name of the entity object in the Bundle object.

Returned value: returns the current Fragment object instance associated with the given reference.

Public void invalidateOptionsMenu ()

If necessary, invalidate the option menu attached to the Activity. This failure state will not be terminated until the Activity is moved to the recovery (resumed) state.

Public abstract void popBackStack ()

Roll back the stack in the top state. This method is executed asynchronously. It will execute the pop-up operation according to the request sequence, but this operation can be executed only after the application returns the control to the event loop.

Public abstract void popBackStack (String name, int flags)

From the Fragment rollback stack of the manager, the final Fragment object specified by the name parameter is displayed. This function is asynchronous and will execute the pop-up operation according to the request sequence. However, this operation will not be executed until the application returns the control to the event loop.

Parameters:

Name ---> if this parameter is not empty, you need to find the Fragment object pointed to by this name in the rollback stack. If it is found, all statuses above this status will pop up. The pop_back_stack_sive sive flag can be used to control whether the naming status itself is to be popped up. If this parameter is null, only the top status will pop up.

Flags ---> it can be either 0 or pop_back_stack_random Sive.

Public abstract void popBackStack (int id, int flags)

The rollback stack pops up for all States above the specified status with the specified ID. This method is asynchronous and will execute pop-up operations according to the request order. However, this operation is not performed until the application returns an event loop of control.

Parameters:

Id ---> this parameter sets the identifier of the status to pop up. If the identified status does not exist, do nothing. The pop_back_stack_sive sive flag can be used to control whether the status identified by the id itself is popped up.

Flags ---> it can be either 0 or pop_back_stack_volume Sive.

Public abstract boolean popBackStackImmediate (int id, int flags)

The method is similar to the popBackStack (int, int) method, but the pop-up operation is executed immediately within the call. It works just like calling the executePendingTransactions () method.

Return Value: if some statuses are displayed, true is returned; otherwise, false is returned.

Public abstract boolean popBackStackImmediate (String name, int flags)

The popBackStack (String, int) method is similar to that of popBackStack. However, the pop-up operation is executed immediately within the call. It works just like calling the executePendingTransactions () method.

Return Value: if some statuses are displayed, true is returned; otherwise, false is returned.

Public abstract boolean popBackStackImmediate ()

The popBackStack () method is similar, but the pop-up operation is executed immediately within the call. It works just like calling the executePendingTransactions () method.

Return Value: if some statuses are displayed, true is returned; otherwise, false is returned.

Public abstract void putFragment (Bundle bundle, String key, Fragment fragment)

Put a specified Fragment object into a Bundle object. This Bundle object can be saved as a persistent state. When the getFragment (Bundle, String) method is called to restore the object, it returns the same Fragment object as the current instance.

Parameters:

Bundle ---> this parameter specifies a Bundle object. During method execution, the specified Fragment object reference will be placed in this Bundle object.

Key ---> this parameter specifies the name of the object in the Bundle object.

Fragment ---> this parameter specifies the reference of the Fragment object to be saved.

Public abstract void removeOnBackStackChangedListener (FragmentManager. OnBackStackChangedListener listener)

Delete a listener that was previously added using the addOnBackStackChangedListener (OnBackStackChangedListener) method.

Public abstract Fragment. SavedState saveFragmentInstanceState (Fragment f)

Saves the current status of the given Fragment object. After creating a new Fragment object instance and adding it to the Fragment manager, you can use this method to create a State object that matches the current state of the Fragment object. Pay attention to the following restrictions when using this method:

1. The Fragment object must be bound to the current FragmentManager object;

2. Create a New Fragment object using the Saved state, which must have the same class type as the Fragment object created in this state.

3. the saved State cannot contain dependencies on other Fragment objects. That is, you cannot use the putFragment (Bundle, String, Fragment) method to save a reference to a Fragment object, this reference may be invalid in subsequent use. Similarly, the target and result code of the Fragment object cannot be included in the State to be saved.

Parameters:

F ---> the Fragment object to save the status.

Return Value:

Generated status object. If you are not interested in the status created by Fragment, this method returns null.

 

 

From FireOfStar's column

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.