added in version 22.1.0
belongs to Maven artifact com.android.support:support-fragment:28.0.0-alpha1

FragmentActivity

public class FragmentActivity
extends Activity implements LifecycleOwner, ViewModelStoreOwner, ActivityCompat.OnRequestPermissionsResultCallback

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ android.support.v4.app.FragmentActivity
Known Direct Subclasses


Base class for activities that want to use the support-based Fragment and Loader APIs.

When using this class as opposed to new platform's built-in fragment and loader support, you must use the getSupportFragmentManager() and getSupportLoaderManager() methods respectively to access those features.

Known limitations:

  • When using the <fragment> tag, this implementation can not use the parent view's ID as the new fragment's ID. You must explicitly specify an ID (or tag) in the <fragment>.

Summary

Inherited constants

From class android.app.Activity
From class android.content.Context
From interface android.content.ComponentCallbacks2

Inherited fields

From class android.app.Activity

Public constructors

FragmentActivity()

Public methods

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

Print the Activity's state into the given stream.

Object getLastCustomNonConfigurationInstance()

Return the value previously returned from onRetainCustomNonConfigurationInstance().

Lifecycle getLifecycle()

Returns the Lifecycle of the provider.

FragmentManager getSupportFragmentManager()

Return the FragmentManager for interacting with fragments associated with this activity.

LoaderManager getSupportLoaderManager()
ViewModelStore getViewModelStore()

Returns the ViewModelStore associated with this activity

void onAttachFragment(Fragment fragment)

Called when a fragment is attached to the activity.

void onBackPressed()

Take care of popping the fragment back stack or finishing the activity as appropriate.

void onConfigurationChanged(Configuration newConfig)

Dispatch configuration change to all fragments.

boolean onCreatePanelMenu(int featureId, Menu menu)

Dispatch to Fragment.onCreateOptionsMenu().

View onCreateView(View parent, String name, Context context, AttributeSet attrs)
View onCreateView(String name, Context context, AttributeSet attrs)
void onLowMemory()

Dispatch onLowMemory() to all fragments.

boolean onMenuItemSelected(int featureId, MenuItem item)

Dispatch context and options menu to fragments.

void onMultiWindowModeChanged(boolean isInMultiWindowMode)

Note: If you override this method you must call super.onMultiWindowModeChanged to correctly dispatch the event to support fragments attached to this activity.

void onPanelClosed(int featureId, Menu menu)

Call onOptionsMenuClosed() on fragments.

void onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

Note: If you override this method you must call super.onPictureInPictureModeChanged to correctly dispatch the event to support fragments attached to this activity.

boolean onPreparePanel(int featureId, View view, Menu menu)

Dispatch onPrepareOptionsMenu() to fragments.

void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)

Callback for the result from requesting permissions.

Object onRetainCustomNonConfigurationInstance()

Use this instead of onRetainNonConfigurationInstance().

final Object onRetainNonConfigurationInstance()

Retain all appropriate fragment state.

void onStateNotSaved()

Hook in to note that fragment state is no longer saved.

void setEnterSharedElementCallback(SharedElementCallback callback)

When makeSceneTransitionAnimation(Activity, android.view.View, String) was used to start an Activity, callback will be called to handle shared elements on the launched Activity.

void setExitSharedElementCallback(SharedElementCallback listener)

When makeSceneTransitionAnimation(Activity, android.view.View, String) was used to start an Activity, listener will be called to handle shared elements on the launching Activity.

void startActivityForResult(Intent intent, int requestCode, Bundle options)
void startActivityForResult(Intent intent, int requestCode)

Modifies the standard behavior to allow results to be delivered to fragments.

void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode)

Called by Fragment.startActivityForResult() to implement its behavior.

void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode, Bundle options)

Called by Fragment.startActivityForResult() to implement its behavior.

void startIntentSenderForResult(IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags)
void startIntentSenderForResult(IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)
void startIntentSenderFromFragment(Fragment fragment, IntentSender intent, int requestCode, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)

Called by Fragment.startIntentSenderForResult() to implement its behavior.

void supportFinishAfterTransition()

Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition.

void supportInvalidateOptionsMenu()

This method was deprecated in API level 26.1.0. Call invalidateOptionsMenu() directly.

void supportPostponeEnterTransition()

Support library version of postponeEnterTransition() that works only on API 21 and later.

void supportStartPostponedEnterTransition()

Support library version of startPostponedEnterTransition() that only works with API 21 and later.

final void validateRequestPermissionsRequestCode(int requestCode)

Protected methods

void onActivityResult(int requestCode, int resultCode, Intent data)

Dispatch incoming result to the correct fragment.

void onCreate(Bundle savedInstanceState)

Perform initialization of all fragments.

void onDestroy()

Destroy all fragments.

void onNewIntent(Intent intent)

Handle onNewIntent() to inform the fragment manager that the state is not saved.

void onPause()

Dispatch onPause() to fragments.

void onPostResume()

Dispatch onResume() to fragments.

void onResume()

Dispatch onResume() to fragments.

void onResumeFragments()

This is the fragment-orientated version of onResume() that you can override to perform operations in the Activity at the same point where its fragments are resumed.

void onSaveInstanceState(Bundle outState)

Save all appropriate fragment state.

void onStart()

Dispatch onStart() to all fragments.

void onStop()

Dispatch onStop() to all fragments.

Inherited methods

From class android.app.Activity
From class android.view.ContextThemeWrapper
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.arch.lifecycle.LifecycleOwner
From interface android.view.LayoutInflater.Factory2
From interface android.view.Window.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener
From interface android.content.ComponentCallbacks2
From interface android.arch.lifecycle.ViewModelStoreOwner
From interface android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback
From interface android.view.LayoutInflater.Factory
From interface android.content.ComponentCallbacks

Public constructors

FragmentActivity

added in version 22.1.0
FragmentActivity ()

Public methods

dump

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

Print the Activity's state into the given stream. This gets invoked if you run "adb shell dumpsys activity ".

Parameters
prefix String: Desired prefix to prepend at each line of output.

fd FileDescriptor: The raw file descriptor that the dump is being sent to.

writer PrintWriter: The PrintWriter to which you should dump your state. This will be closed for you after you return.

args String: additional arguments to the dump request.

getLastCustomNonConfigurationInstance

added in version 22.1.0
Object getLastCustomNonConfigurationInstance ()

Return the value previously returned from onRetainCustomNonConfigurationInstance().

Returns
Object

getLifecycle

added in version 26.1.0
Lifecycle getLifecycle ()

Returns the Lifecycle of the provider.

Returns
Lifecycle The lifecycle of the provider.

getSupportFragmentManager

added in version 22.1.0
FragmentManager getSupportFragmentManager ()

Return the FragmentManager for interacting with fragments associated with this activity.

Returns
FragmentManager

getSupportLoaderManager

added in version 22.1.0
LoaderManager getSupportLoaderManager ()

Returns
LoaderManager

getViewModelStore

added in version 27.1.0
ViewModelStore getViewModelStore ()

Returns the ViewModelStore associated with this activity

Returns
ViewModelStore a ViewModelStore

onAttachFragment

added in version 22.1.0
void onAttachFragment (Fragment fragment)

Called when a fragment is attached to the activity.

This is called after the attached fragment's onAttach and before the attached fragment's onCreate if the fragment has not yet had a previous call to onCreate.

Parameters
fragment Fragment

onBackPressed

void onBackPressed ()

Take care of popping the fragment back stack or finishing the activity as appropriate.

onConfigurationChanged

void onConfigurationChanged (Configuration newConfig)

Dispatch configuration change to all fragments.

Parameters
newConfig Configuration

onCreatePanelMenu

boolean onCreatePanelMenu (int featureId, 
                Menu menu)

Dispatch to Fragment.onCreateOptionsMenu().

Parameters
featureId int

menu Menu

Returns
boolean

onCreateView

View onCreateView (View parent, 
                String name, 
                Context context, 
                AttributeSet attrs)

Parameters
parent View

name String

context Context

attrs AttributeSet

Returns
View

onCreateView

View onCreateView (String name, 
                Context context, 
                AttributeSet attrs)

Parameters
name String

context Context

attrs AttributeSet

Returns
View

onLowMemory

void onLowMemory ()

Dispatch onLowMemory() to all fragments.

onMenuItemSelected

boolean onMenuItemSelected (int featureId, 
                MenuItem item)

Dispatch context and options menu to fragments.

Parameters
featureId int

item MenuItem

Returns
boolean

onMultiWindowModeChanged

added in version 26.1.0
void onMultiWindowModeChanged (boolean isInMultiWindowMode)

Note: If you override this method you must call super.onMultiWindowModeChanged to correctly dispatch the event to support fragments attached to this activity.

Parameters
isInMultiWindowMode boolean: True if the activity is in multi-window mode.

onPanelClosed

void onPanelClosed (int featureId, 
                Menu menu)

Call onOptionsMenuClosed() on fragments.

Parameters
featureId int

menu Menu

onPictureInPictureModeChanged

added in version 26.1.0
void onPictureInPictureModeChanged (boolean isInPictureInPictureMode)

Note: If you override this method you must call super.onPictureInPictureModeChanged to correctly dispatch the event to support fragments attached to this activity.

Parameters
isInPictureInPictureMode boolean: True if the activity is in picture-in-picture mode.

onPreparePanel

boolean onPreparePanel (int featureId, 
                View view, 
                Menu menu)

Dispatch onPrepareOptionsMenu() to fragments.

Parameters
featureId int

view View

menu Menu

Returns
boolean

onRequestPermissionsResult

void onRequestPermissionsResult (int requestCode, 
                String[] permissions, 
                int[] grantResults)

Callback for the result from requesting permissions. This method is invoked for every call on requestPermissions(String[], int).

Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.

Parameters
requestCode int: The request code passed in requestPermissions(String[], int).

permissions String: The requested permissions. Never null.

grantResults int: The grant results for the corresponding permissions which is either PERMISSION_GRANTED or PERMISSION_DENIED. Never null.

onRetainCustomNonConfigurationInstance

added in version 22.1.0
Object onRetainCustomNonConfigurationInstance ()

Use this instead of onRetainNonConfigurationInstance(). Retrieve later with getLastCustomNonConfigurationInstance().

Returns
Object

onRetainNonConfigurationInstance

added in version 22.1.0
Object onRetainNonConfigurationInstance ()

Retain all appropriate fragment state. You can NOT override this yourself! Use onRetainCustomNonConfigurationInstance() if you want to retain your own state.

Returns
Object

onStateNotSaved

void onStateNotSaved ()

Hook in to note that fragment state is no longer saved.

setEnterSharedElementCallback

added in version 22.1.0
void setEnterSharedElementCallback (SharedElementCallback callback)

When makeSceneTransitionAnimation(Activity, android.view.View, String) was used to start an Activity, callback will be called to handle shared elements on the launched Activity. This requires FEATURE_CONTENT_TRANSITIONS.

Parameters
callback SharedElementCallback: Used to manipulate shared element transitions on the launched Activity.

setExitSharedElementCallback

added in version 22.1.0
void setExitSharedElementCallback (SharedElementCallback listener)

When makeSceneTransitionAnimation(Activity, android.view.View, String) was used to start an Activity, listener will be called to handle shared elements on the launching Activity. Most calls will only come when returning from the started Activity. This requires FEATURE_CONTENT_TRANSITIONS.

Parameters
listener SharedElementCallback: Used to manipulate shared element transitions on the launching Activity.

startActivityForResult

void startActivityForResult (Intent intent, 
                int requestCode, 
                Bundle options)

Parameters
intent Intent

requestCode int

options Bundle

startActivityForResult

void startActivityForResult (Intent intent, 
                int requestCode)

Modifies the standard behavior to allow results to be delivered to fragments. This imposes a restriction that requestCode be <= 0xffff.

Parameters
intent Intent

requestCode int

startActivityFromFragment

added in version 22.1.0
void startActivityFromFragment (Fragment fragment, 
                Intent intent, 
                int requestCode)

Called by Fragment.startActivityForResult() to implement its behavior.

Parameters
fragment Fragment

intent Intent

requestCode int

startActivityFromFragment

added in version 24.1.0
void startActivityFromFragment (Fragment fragment, 
                Intent intent, 
                int requestCode, 
                Bundle options)

Called by Fragment.startActivityForResult() to implement its behavior.

Parameters
fragment Fragment

intent Intent

requestCode int

options Bundle

startIntentSenderForResult

void startIntentSenderForResult (IntentSender intent, 
                int requestCode, 
                Intent fillInIntent, 
                int flagsMask, 
                int flagsValues, 
                int extraFlags)

Parameters
intent IntentSender

requestCode int

fillInIntent Intent

flagsMask int

flagsValues int

extraFlags int

Throws
IntentSender.SendIntentException

startIntentSenderForResult

void startIntentSenderForResult (IntentSender intent, 
                int requestCode, 
                Intent fillInIntent, 
                int flagsMask, 
                int flagsValues, 
                int extraFlags, 
                Bundle options)

Parameters
intent IntentSender

requestCode int

fillInIntent Intent

flagsMask int

flagsValues int

extraFlags int

options Bundle

Throws
IntentSender.SendIntentException

startIntentSenderFromFragment

added in version 24.1.0
void startIntentSenderFromFragment (Fragment fragment, 
                IntentSender intent, 
                int requestCode, 
                Intent fillInIntent, 
                int flagsMask, 
                int flagsValues, 
                int extraFlags, 
                Bundle options)

Called by Fragment.startIntentSenderForResult() to implement its behavior.

Parameters
fragment Fragment

intent IntentSender

requestCode int

fillInIntent Intent

flagsMask int

flagsValues int

extraFlags int

options Bundle

Throws
IntentSender.SendIntentException

supportFinishAfterTransition

added in version 22.1.0
void supportFinishAfterTransition ()

Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition. When the exit Transition completes, finish() is called. If no entry Transition was used, finish() is called immediately and the Activity exit Transition is run.

On Android 4.4 or lower, this method only finishes the Activity with no special exit transition.

supportInvalidateOptionsMenu

added in version 22.1.0
void supportInvalidateOptionsMenu ()

This method was deprecated in API level 26.1.0.
Call invalidateOptionsMenu() directly.

Support library version of invalidateOptionsMenu().

Invalidate the activity's options menu. This will cause relevant presentations of the menu to fully update via calls to onCreateOptionsMenu and onPrepareOptionsMenu the next time the menu is requested.

supportPostponeEnterTransition

added in version 22.1.0
void supportPostponeEnterTransition ()

Support library version of postponeEnterTransition() that works only on API 21 and later.

supportStartPostponedEnterTransition

added in version 22.1.0
void supportStartPostponedEnterTransition ()

Support library version of startPostponedEnterTransition() that only works with API 21 and later.

validateRequestPermissionsRequestCode

added in version 24.1.0
void validateRequestPermissionsRequestCode (int requestCode)

Parameters
requestCode int

Protected methods

onActivityResult

void onActivityResult (int requestCode, 
                int resultCode, 
                Intent data)

Dispatch incoming result to the correct fragment.

Parameters
requestCode int

resultCode int

data Intent

onCreate

added in version 26.1.0
void onCreate (Bundle savedInstanceState)

Perform initialization of all fragments.

Parameters
savedInstanceState Bundle

onDestroy

void onDestroy ()

Destroy all fragments.

onNewIntent

void onNewIntent (Intent intent)

Handle onNewIntent() to inform the fragment manager that the state is not saved. If you are handling new intents and may be making changes to the fragment state, you want to be sure to call through to the super-class here first. Otherwise, if your state is saved but the activity is not stopped, you could get an onNewIntent() call which happens before onResume() and trying to perform fragment operations at that point will throw IllegalStateException because the fragment manager thinks the state is still saved.

Parameters
intent Intent

onPause

void onPause ()

Dispatch onPause() to fragments.

onPostResume

void onPostResume ()

Dispatch onResume() to fragments.

onResume

void onResume ()

Dispatch onResume() to fragments. Note that for better inter-operation with older versions of the platform, at the point of this call the fragments attached to the activity are not resumed. This means that in some cases the previous state may still be saved, not allowing fragment transactions that modify the state. To correctly interact with fragments in their proper state, you should instead override onResumeFragments().

onResumeFragments

added in version 22.1.0
void onResumeFragments ()

This is the fragment-orientated version of onResume() that you can override to perform operations in the Activity at the same point where its fragments are resumed. Be sure to always call through to the super-class.

onSaveInstanceState

added in version 26.1.0
void onSaveInstanceState (Bundle outState)

Save all appropriate fragment state.

Parameters
outState Bundle

onStart

void onStart ()

Dispatch onStart() to all fragments.

onStop

void onStop ()

Dispatch onStop() to all fragments.