{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
class FragmentActivity
Base class for activities that want to use the support-based Fragments
.
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>
.
Public constructors |
|
---|---|
Default constructor for FragmentActivity. |
|
FragmentActivity(contentLayoutId: Int) Alternate constructor that can be used to provide a default layout that will be inflated as part of |
Public functions |
|
---|---|
Unit |
dump( Print the Activity's state into the given stream. |
FragmentManager |
Return the FragmentManager for interacting with fragments associated with this activity. |
LoaderManager |
This function is deprecated. Use LoaderManager.getInstance(this). |
Unit |
This function is deprecated. The responsibility for listening for fragments being attached has been moved to FragmentManager. |
Unit |
onConfigurationChanged(newConfig: Configuration) Dispatch configuration change to all fragments. |
Boolean |
onCreatePanelMenu(featureId: Int, menu: Menu) Dispatch to Fragment.onCreateOptionsMenu(). |
View? |
onCreateView( |
View? |
onCreateView(name: String, context: Context, attrs: AttributeSet) |
Unit |
Dispatch onLowMemory() to all fragments. |
Boolean |
onMenuItemSelected(featureId: Int, item: MenuItem) Dispatch context and options menu to fragments. |
Unit |
onMultiWindowModeChanged(isInMultiWindowMode: Boolean) Note: If you override this method you must call |
Unit |
onPanelClosed(featureId: Int, menu: Menu) Call onOptionsMenuClosed() on fragments. |
Unit |
onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) Note: If you override this method you must call |
Boolean |
onPreparePanel(featureId: Int, view: View?, menu: Menu) Dispatch onPrepareOptionsMenu() to fragments. |
Unit |
|
Unit |
Hook in to note that fragment state is no longer saved. |
Unit |
setEnterSharedElementCallback(callback: SharedElementCallback?) When makeSceneTransitionAnimation was used to start an Activity, callbackwill be called to handle shared elements on the launched Activity. |
Unit |
setExitSharedElementCallback(listener: SharedElementCallback?) When makeSceneTransitionAnimation was used to start an Activity, listenerwill be called to handle shared elements on the launching Activity. |
Unit |
startActivityFromFragment( Called by Fragment.startActivityForResult() to implement its behavior. |
Unit |
startActivityFromFragment( Called by Fragment.startActivityForResult() to implement its behavior. |
Unit |
This function is deprecated. Fragments should use |
Unit |
Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition. |
Unit |
This function is deprecated. Call Activity#invalidateOptionsMenu directly. |
Unit |
Support library version of postponeEnterTransition that works only on API 21 and later. |
Unit |
Support library version of startPostponedEnterTransition that only works with API 21 and later. |
Unit |
This function is deprecated. there are no longer any restrictions on permissions requestCodes. |
FragmentActivity()
Default constructor for FragmentActivity. All Activities must have a default constructor for API 27 and lower devices or when using the default android.app.AppComponentFactory.
FragmentActivity(contentLayoutId: Int)
Alternate constructor that can be used to provide a default layout that will be inflated as part of super.onCreate(savedInstanceState)
.
This should generally be called from your constructor that takes no parameters, as is required for API 27 and lower or when using the default android.app.AppComponentFactory.
See also | |
---|---|
FragmentActivity |
#FragmentActivity() |
fun dump(
prefix: String,
fd: FileDescriptor?,
writer: PrintWriter,
args: Array<String>?
): Unit
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: Array<String>? |
additional arguments to the dump request. |
fun getSupportFragmentManager(): FragmentManager
Return the FragmentManager for interacting with fragments associated with this activity.
funonAttachFragment(fragment: Fragment): Unit
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
.
fun onConfigurationChanged(newConfig: Configuration): Unit
Dispatch configuration change to all fragments.
fun onCreatePanelMenu(featureId: Int, menu: Menu): Boolean
Dispatch to Fragment.onCreateOptionsMenu().
fun onCreateView(
parent: View?,
name: String,
context: Context,
attrs: AttributeSet
): View?
fun onMenuItemSelected(featureId: Int, item: MenuItem): Boolean
Dispatch context and options menu to fragments.
fun onMultiWindowModeChanged(isInMultiWindowMode: Boolean): Unit
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. |
fun onPanelClosed(featureId: Int, menu: Menu): Unit
Call onOptionsMenuClosed() on fragments.
fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean): Unit
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. |
fun onPreparePanel(featureId: Int, view: View?, menu: Menu): Boolean
Dispatch onPrepareOptionsMenu() to fragments.
fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: Array<Int>
): Unit
fun setEnterSharedElementCallback(callback: SharedElementCallback?): Unit
When makeSceneTransitionAnimation was used to start an Activity, callbackwill be called to handle shared elements on the launched Activity. This requires Window#FEATURE_CONTENT_TRANSITIONS.
Parameters | |
---|---|
callback: SharedElementCallback? |
Used to manipulate shared element transitions on the launched Activity. |
fun setExitSharedElementCallback(listener: SharedElementCallback?): Unit
When makeSceneTransitionAnimation was used to start an Activity, listenerwill be called to handle shared elements on the launching Activity. Most calls will only come when returning from the started Activity. This requires Window#FEATURE_CONTENT_TRANSITIONS.
Parameters | |
---|---|
listener: SharedElementCallback? |
Used to manipulate shared element transitions on the launching Activity. |
fun startActivityFromFragment(
fragment: Fragment,
intent: Intent,
requestCode: Int
): Unit
Called by Fragment.startActivityForResult() to implement its behavior.
Parameters | |
---|---|
fragment: Fragment |
the Fragment to start the activity from. |
intent: Intent |
The intent to start. |
requestCode: Int |
The request code to be returned in |
fun startActivityFromFragment(
fragment: Fragment,
intent: Intent,
requestCode: Int,
options: Bundle?
): Unit
Called by Fragment.startActivityForResult() to implement its behavior.
Parameters | |
---|---|
fragment: Fragment |
the Fragment to start the activity from. |
intent: Intent |
The intent to start. |
requestCode: Int |
The request code to be returned in |
options: Bundle? |
Additional options for how the Activity should be started. See Context#startActivity(Intent, Bundle) for more details. This value may be null. |
funstartIntentSenderFromFragment(
fragment: Fragment,
intent: IntentSender,
requestCode: Int,
fillInIntent: Intent?,
flagsMask: Int,
flagsValues: Int,
extraFlags: Int,
options: Bundle?
): Unit
Called by Fragment.startIntentSenderForResult() to implement its behavior.
Parameters | |
---|---|
fragment: Fragment |
the Fragment to start the intent sender from. |
intent: IntentSender |
The IntentSender to launch. |
requestCode: Int |
The request code to be returned in |
fillInIntent: Intent? |
If non-null, this will be provided as the intent parameter to IntentSender#sendIntent(Context, int, Intent, IntentSender.OnFinished, Handler). This value may be null. |
flagsMask: Int |
Intent flags in the original IntentSender that you would like to change. |
flagsValues: Int |
Desired values for any bits set in |
extraFlags: Int |
Always set to 0. |
options: Bundle? |
Additional options for how the Activity should be started. See Context#startActivity(Intent, Bundle) for more details. This value may be null. |
Throws | |
---|---|
android.content.IntentSender.SendIntentException |
if the call fails to execute. |
fun supportFinishAfterTransition(): Unit
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.
funsupportInvalidateOptionsMenu(): Unit
Support library version of Activity#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.
fun supportPostponeEnterTransition(): Unit
Support library version of postponeEnterTransition that works only on API 21 and later.
fun supportStartPostponedEnterTransition(): Unit
Support library version of startPostponedEnterTransition that only works with API 21 and later.
funvalidateRequestPermissionsRequestCode(requestCode: Int): Unit