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, 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, string key, 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.

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.