FragmentManager
public
abstract
class
FragmentManager
extends Object
| java.lang.Object | |
| ↳ | android.app.FragmentManager |
Interface for interacting with Fragment objects inside of an
Activity
Developer Guides
For more information about using fragments, read the Fragments developer guide.
HONEYCOMB, a version of the API
at is also available for use on older platforms through
FragmentActivity. See the blog post
Fragments For All for more details.
Summary
Nested classes | |
|---|---|
interface |
FragmentManager.BackStackEntry
Representation of an entry on the fragment back stack, as created
with |
interface |
FragmentManager.OnBackStackChangedListener
Interface to watch for changes to the back stack. |
Constants | |
|---|---|
int |
POP_BACK_STACK_INCLUSIVE
Flag for |
Public constructors | |
|---|---|
FragmentManager()
|
|
Public methods | |
|---|---|
abstract
void
|
addOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener listener)
Add a new listener for changes to the fragment back stack. |
abstract
FragmentTransaction
|
beginTransaction()
Start a series of edit operations on the Fragments associated with this FragmentManager. |
abstract
void
|
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
Print the FragmentManager's state into the given stream. |
static
void
|
enableDebugLogging(boolean enabled)
Control whether the framework's internal fragment manager debugging logs are turned on. |
abstract
boolean
|
executePendingTransactions()
After a |
abstract
Fragment
|
findFragmentById(int id)
Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction. |
abstract
Fragment
|
findFragmentByTag(String tag)
Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction. |
abstract
FragmentManager.BackStackEntry
|
getBackStackEntryAt(int index)
Return the BackStackEntry at index index in the back stack; where the item on the bottom of the stack has index 0. |
abstract
int
|
getBackStackEntryCount()
Return the number of entries currently in the back stack. |
abstract
Fragment
|
getFragment(Bundle bundle, String key)
Retrieve the current Fragment instance for a reference previously
placed with |
void
|
invalidateOptionsMenu()
Invalidate the attached activity's options menu as necessary. |
abstract
boolean
|
isDestroyed()
Returns true if the final |
abstract
void
|
popBackStack()
Pop the top state off the back stack. |
abstract
void
|
popBackStack(int id, int flags)
Pop all back stack states up to the one with the given identifier. |
abstract
void
|
popBackStack(String name, int flags)
Pop the last fragment transition from the manager's fragment back stack. |
abstract
boolean
|
popBackStackImmediate(int id, int flags)
Like |
abstract
boolean
|
popBackStackImmediate(String name, int flags)
Like |
abstract
boolean
|
popBackStackImmediate()
Like |
abstract
void
|
putFragment(Bundle bundle, String key, Fragment fragment)
Put a reference to a fragment in a Bundle. |
abstract
void
|
removeOnBackStackChangedListener(FragmentManager.OnBackStackChangedListener listener)
Remove a listener that was previously added with
|
abstract
Fragment.SavedState
|
saveFragmentInstanceState(Fragment f)
Save the current instance state of the given Fragment. |
Inherited methods | |
|---|---|
java.lang.Object
| |
Constants
POP_BACK_STACK_INCLUSIVE
int POP_BACK_STACK_INCLUSIVE
Flag for popBackStack(String, int)
and popBackStack(int, int): If set, and the name or ID of
a back stack entry has been supplied, then all matching entries will
be consumed until one that doesn't match is found or the bottom of
the stack is reached. Otherwise, all entries up to but not including that entry
will be removed.
Constant Value: 1 (0x00000001)
Public constructors
Public methods
addOnBackStackChangedListener
void addOnBackStackChangedListener (FragmentManager.OnBackStackChangedListener listener)
Add a new listener for changes to the fragment back stack.
| Parameters | |
|---|---|
listener |
FragmentManager.OnBackStackChangedListener
|
beginTransaction
FragmentTransaction beginTransaction ()
Start a series of edit operations on the Fragments associated with this FragmentManager.
Note: A fragment transaction can only be created/committed prior
to an activity saving its state. If you try to commit a transaction
after Activity.onSaveInstanceState()
(and prior to a following Activity.onStart
or Activity.onResume(), you will get an error.
This is because the framework takes care of saving your current fragments
in the state, and if changes are made after the state is saved then they
will be lost.
| Returns | |
|---|---|
FragmentTransaction |
|
dump
void dump (String prefix, FileDescriptor fd, PrintWriter writer, String[] args)
Print the FragmentManager's state into the given stream.
| Parameters | |
|---|---|
prefix |
String:
Text to print at the front of each line. |
fd |
FileDescriptor:
The raw file descriptor that the dump is being sent to. |
writer |
PrintWriter:
A PrintWriter to which the dump is to be set. |
args |
String:
Additional arguments to the dump request.
|
enableDebugLogging
void enableDebugLogging (boolean enabled)
Control whether the framework's internal fragment manager debugging logs are turned on. If enabled, you will see output in logcat as the framework performs fragment operations.
| Parameters | |
|---|---|
enabled |
boolean
|
executePendingTransactions
boolean executePendingTransactions ()
After a FragmentTransaction is committed with
FragmentTransaction.commit(), it
is scheduled to be executed asynchronously on the process's main thread.
If you want to immediately executing any such pending operations, you
can call this function (only from the main thread) to do so. Note that
all callbacks and other related behavior will be done from within this
call, so be careful about where this is called from.
| Returns | |
|---|---|
boolean |
Returns true if there were any pending transactions to be executed. |
findFragmentById
Fragment findFragmentById (int id)
Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction. This first searches through fragments that are currently added to the manager's activity; if no such fragment is found, then all fragments currently on the back stack associated with this ID are searched.
| Parameters | |
|---|---|
id |
int
|
| Returns | |
|---|---|
Fragment |
The fragment if found or null otherwise. |
findFragmentByTag
Fragment findFragmentByTag (String tag)
Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction. This first searches through fragments that are currently added to the manager's activity; if no such fragment is found, then all fragments currently on the back stack are searched.
| Parameters | |
|---|---|
tag |
String
|
| Returns | |
|---|---|
Fragment |
The fragment if found or null otherwise. |
getBackStackEntryAt
FragmentManager.BackStackEntry getBackStackEntryAt (int index)
Return the BackStackEntry at index index in the back stack; where the item on the bottom of the stack has index 0.
| Parameters | |
|---|---|
index |
int
|
| Returns | |
|---|---|
FragmentManager.BackStackEntry |
|
getBackStackEntryCount
int getBackStackEntryCount ()
Return the number of entries currently in the back stack.
| Returns | |
|---|---|
int |
|
getFragment
Fragment getFragment (Bundle bundle, String key)
Retrieve the current Fragment instance for a reference previously
placed with putFragment(Bundle, String, Fragment).
| Parameters | |
|---|---|
bundle |
Bundle:
The bundle from which to retrieve the fragment reference. |
key |
String:
The name of the entry in the bundle. |
| Returns | |
|---|---|
Fragment |
Returns the current Fragment instance that is associated with the given reference. |
invalidateOptionsMenu
void invalidateOptionsMenu ()
Invalidate the attached activity's options menu as necessary. This may end up being deferred until we move to the resumed state.
isDestroyed
boolean isDestroyed ()
Returns true if the final Activity.onDestroy()
call has been made on the FragmentManager's Activity, so this instance is now dead.
| Returns | |
|---|---|
boolean |
|
popBackStack
void popBackStack ()
Pop the top state off the back stack. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.
popBackStack
void popBackStack (int id,
int flags)
Pop all back stack states up to the one with the given identifier. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.
| Parameters | |
|---|---|
id |
int:
Identifier of the stated to be popped. If no identifier exists,
false is returned.
The identifier is the number returned by
FragmentTransaction.commit(). The
POP_BACK_STACK_INCLUSIVE flag can be used to control whether
the named state itself is popped. |
flags |
int:
Either 0 or POP_BACK_STACK_INCLUSIVE.
|
popBackStack
void popBackStack (String name, int flags)
Pop the last fragment transition from the manager's fragment back stack. If there is nothing to pop, false is returned. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.
| Parameters | |
|---|---|
name |
String:
If non-null, this is the name of a previous back state
to look for; if found, all states up to that state will be popped. The
POP_BACK_STACK_INCLUSIVE flag can be used to control whether
the named state itself is popped. If null, only the top state is popped. |
flags |
int:
Either 0 or POP_BACK_STACK_INCLUSIVE.
|
popBackStackImmediate
boolean popBackStackImmediate (int id,
int flags)
Like popBackStack(int, int), but performs the operation immediately
inside of the call. This is like calling executePendingTransactions()
afterwards.
| Parameters | |
|---|---|
id |
int
|
flags |
int
|
| Returns | |
|---|---|
boolean |
Returns true if there was something popped, else false. |
popBackStackImmediate
boolean popBackStackImmediate (String name, int flags)
Like popBackStack(String, int), but performs the operation immediately
inside of the call. This is like calling executePendingTransactions()
afterwards.
| Parameters | |
|---|---|
name |
String
|
flags |
int
|
| Returns | |
|---|---|
boolean |
Returns true if there was something popped, else false. |
popBackStackImmediate
boolean popBackStackImmediate ()
Like popBackStack(), but performs the operation immediately
inside of the call. This is like calling executePendingTransactions()
afterwards.
| Returns | |
|---|---|
boolean |
Returns true if there was something popped, else false. |
putFragment
void putFragment (Bundle bundle, String key, Fragment fragment)
Put a reference to a fragment in a Bundle. This Bundle can be
persisted as saved state, and when later restoring
getFragment(Bundle, String) will return the current
instance of the same fragment.
| Parameters | |
|---|---|
bundle |
Bundle:
The bundle in which to put the fragment reference. |
key |
String:
The name of the entry in the bundle. |
fragment |
Fragment:
The Fragment whose reference is to be stored.
|
removeOnBackStackChangedListener
void removeOnBackStackChangedListener (FragmentManager.OnBackStackChangedListener listener)
Remove a listener that was previously added with
addOnBackStackChangedListener(OnBackStackChangedListener).
| Parameters | |
|---|---|
listener |
FragmentManager.OnBackStackChangedListener
|
saveFragmentInstanceState
Fragment.SavedState saveFragmentInstanceState (Fragment f)
Save the current instance state of the given Fragment. This can be used later when creating a new instance of the Fragment and adding it to the fragment manager, to have it create itself to match the current state returned here. Note that there are limits on how this can be used:
- The Fragment must currently be attached to the FragmentManager.
- A new Fragment created using this saved state must be the same class type as the Fragment it was created from.
- The saved state can not contain dependencies on other fragments --
that is it can't use
putFragment(Bundle, String, Fragment)to store a fragment reference because that reference may not be valid when this saved state is later used. Likewise the Fragment's target and result code are not included in this state.
| Parameters | |
|---|---|
f |
Fragment:
The Fragment whose state is to be saved. |
| Returns | |
|---|---|
Fragment.SavedState |
The generated state. This will be null if there was no interesting state created by the fragment. |
Interfaces
- ActionBar.OnMenuVisibilityListener
- ActionBar.OnNavigationListener
- ActionBar.TabListener
- AlarmManager.OnAlarmListener
- Application.ActivityLifecycleCallbacks
- Application.OnProvideAssistDataListener
- AppOpsManager.OnOpChangedListener
- DatePickerDialog.OnDateSetListener
- FragmentBreadCrumbs.OnBreadCrumbClickListener
- FragmentManager.BackStackEntry
- FragmentManager.OnBackStackChangedListener
- KeyguardManager.OnKeyguardExitResult
- LoaderManager.LoaderCallbacks
- Notification.Action.Extender
- Notification.Extender
- PendingIntent.OnFinished
- SearchManager.OnCancelListener
- SearchManager.OnDismissListener
- SharedElementCallback.OnSharedElementsReadyListener
- TimePickerDialog.OnTimeSetListener
- UiAutomation.AccessibilityEventFilter
- UiAutomation.OnAccessibilityEventListener
Classes
- ActionBar
- ActionBar.LayoutParams
- ActionBar.Tab
- Activity
- ActivityGroup
- ActivityManager
- ActivityManager.AppTask
- ActivityManager.MemoryInfo
- ActivityManager.ProcessErrorStateInfo
- ActivityManager.RecentTaskInfo
- ActivityManager.RunningAppProcessInfo
- ActivityManager.RunningServiceInfo
- ActivityManager.RunningTaskInfo
- ActivityManager.TaskDescription
- ActivityOptions
- AlarmManager
- AlarmManager.AlarmClockInfo
- AlertDialog
- AlertDialog.Builder
- AliasActivity
- Application
- ApplicationErrorReport
- ApplicationErrorReport.AnrInfo
- ApplicationErrorReport.BatteryInfo
- ApplicationErrorReport.CrashInfo
- ApplicationErrorReport.RunningServiceInfo
- AppOpsManager
- AutomaticZenRule
- DatePickerDialog
- Dialog
- DialogFragment
- DownloadManager
- DownloadManager.Query
- DownloadManager.Request
- ExpandableListActivity
- Fragment
- Fragment.SavedState
- FragmentBreadCrumbs
- FragmentContainer
- FragmentController
- FragmentHostCallback
- FragmentManager
- FragmentManagerNonConfig
- FragmentTransaction
- Instrumentation
- Instrumentation.ActivityMonitor
- Instrumentation.ActivityResult
- IntentService
- KeyguardManager
- KeyguardManager.KeyguardLock
- LauncherActivity
- LauncherActivity.IconResizer
- LauncherActivity.ListItem
- ListActivity
- ListFragment
- LoaderManager
- LocalActivityManager
- MediaRouteActionProvider
- MediaRouteButton
- NativeActivity
- Notification
- Notification.Action
- Notification.Action.Builder
- Notification.Action.WearableExtender
- Notification.BigPictureStyle
- Notification.BigTextStyle
- Notification.Builder
- Notification.CarExtender
- Notification.CarExtender.Builder
- Notification.CarExtender.UnreadConversation
- Notification.DecoratedCustomViewStyle
- Notification.DecoratedMediaCustomViewStyle
- Notification.InboxStyle
- Notification.MediaStyle
- Notification.MessagingStyle
- Notification.MessagingStyle.Message
- Notification.Style
- Notification.WearableExtender
- NotificationManager
- NotificationManager.Policy
- PendingIntent
- Presentation
- ProgressDialog
- RemoteInput
- RemoteInput.Builder
- SearchableInfo
- SearchManager
- Service
- SharedElementCallback
- TabActivity
- TaskStackBuilder
- TimePickerDialog
- UiAutomation
- UiModeManager
- VoiceInteractor
- VoiceInteractor.AbortVoiceRequest
- VoiceInteractor.CommandRequest
- VoiceInteractor.CompleteVoiceRequest
- VoiceInteractor.ConfirmationRequest
- VoiceInteractor.PickOptionRequest
- VoiceInteractor.PickOptionRequest.Option
- VoiceInteractor.Prompt
- VoiceInteractor.Request
- WallpaperInfo
- WallpaperManager
Exceptions

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
