{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public 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(@NonNull int contentLayoutId) Alternate constructor that can be used to provide a default layout that will be inflated as part of |
Public methods |
|
---|---|
@NonNull void |
dump( Print the Activity's state into the given stream. |
@NonNull FragmentManager |
Return the FragmentManager for interacting with fragments associated with this activity. |
@NonNull LoaderManager |
This method is deprecated. Use LoaderManager.getInstance(this). |
@NonNull void |
This method is deprecated. The responsibility for listening for fragments being attached has been moved to FragmentManager. |
@NonNull void |
onConfigurationChanged(@NonNull Configuration newConfig) Dispatch configuration change to all fragments. |
@NonNull boolean |
onCreatePanelMenu(@NonNull int featureId, @NonNull Menu menu) Dispatch to Fragment.onCreateOptionsMenu(). |
@Nullable View |
|
@Nullable View |
onCreateView( |
@NonNull void |
Dispatch onLowMemory() to all fragments. |
@NonNull boolean |
onMenuItemSelected(@NonNull int featureId, @NonNull MenuItem item) Dispatch context and options menu to fragments. |
@NonNull void |
onMultiWindowModeChanged(@NonNull boolean isInMultiWindowMode) Note: If you override this method you must call |
@NonNull void |
onPanelClosed(@NonNull int featureId, @NonNull Menu menu) Call onOptionsMenuClosed() on fragments. |
@NonNull void |
onPictureInPictureModeChanged(@NonNull boolean isInPictureInPictureMode) Note: If you override this method you must call |
@NonNull boolean |
onPreparePanel( Dispatch onPrepareOptionsMenu() to fragments. |
@NonNull void |
|
@NonNull void |
Hook in to note that fragment state is no longer saved. |
@NonNull void |
setEnterSharedElementCallback(@Nullable SharedElementCallback callback) When makeSceneTransitionAnimation was used to start an Activity, callbackwill be called to handle shared elements on the launched Activity. |
@NonNull void |
setExitSharedElementCallback(@Nullable SharedElementCallback listener) When makeSceneTransitionAnimation was used to start an Activity, listenerwill be called to handle shared elements on the launching Activity. |
@NonNull void |
startActivityFromFragment( Called by Fragment.startActivityForResult() to implement its behavior. |
@NonNull void |
startActivityFromFragment( Called by Fragment.startActivityForResult() to implement its behavior. |
@NonNull void |
This method is deprecated. Fragments should use |
@NonNull void |
Reverses the Activity Scene entry Transition and triggers the calling Activity to reverse its exit Transition. |
@NonNull void |
This method is deprecated. Call Activity#invalidateOptionsMenu directly. |
@NonNull void |
Support library version of postponeEnterTransition that works only on API 21 and later. |
@NonNull void |
Support library version of startPostponedEnterTransition that only works with API 21 and later. |
final @NonNull void |
This method is deprecated. there are no longer any restrictions on permissions requestCodes. |
@NonNull
public 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.
@NonNull
public FragmentActivity(@NonNull int contentLayoutId)
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() |
@NonNull
public void dump(
@NonNull String prefix,
@Nullable FileDescriptor fd,
@NonNull PrintWriter writer,
@Nullable Array<@NonNull String> args
)
Print the Activity's state into the given stream. This gets invoked if you run "adb shell dumpsys activity ".
Parameters | |
---|---|
@NonNull String prefix |
Desired prefix to prepend at each line of output. |
@Nullable FileDescriptor fd |
The raw file descriptor that the dump is being sent to. |
@NonNull PrintWriter writer |
The PrintWriter to which you should dump your state. This will be closed for you after you return. |
@Nullable Array<@NonNull String> args |
additional arguments to the dump request. |
@NonNull
public FragmentManager getSupportFragmentManager()
Return the FragmentManager for interacting with fragments associated with this activity.
@NonNull
public voidonAttachFragment(@NonNull 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
.
@NonNull
public void onConfigurationChanged(@NonNull Configuration newConfig)
Dispatch configuration change to all fragments.
@NonNull
public boolean onCreatePanelMenu(@NonNull int featureId, @NonNull Menu menu)
Dispatch to Fragment.onCreateOptionsMenu().
@Nullable
@NonNull
public View onCreateView(
@Nullable View parent,
@NonNull String name,
@NonNull Context context,
@NonNull AttributeSet attrs
)
@Nullable
@NonNull
public View onCreateView(
@NonNull String name,
@NonNull Context context,
@NonNull AttributeSet attrs
)
@NonNull
public boolean onMenuItemSelected(@NonNull int featureId, @NonNull MenuItem item)
Dispatch context and options menu to fragments.
@NonNull
public void onMultiWindowModeChanged(@NonNull 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 | |
---|---|
@NonNull boolean isInMultiWindowMode |
True if the activity is in multi-window mode. |
@NonNull
public void onPanelClosed(@NonNull int featureId, @NonNull Menu menu)
Call onOptionsMenuClosed() on fragments.
@NonNull
public void onPictureInPictureModeChanged(@NonNull 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 | |
---|---|
@NonNull boolean isInPictureInPictureMode |
True if the activity is in picture-in-picture mode. |
@NonNull
public boolean onPreparePanel(
@NonNull int featureId,
@Nullable View view,
@NonNull Menu menu
)
Dispatch onPrepareOptionsMenu() to fragments.
@NonNull
public void onRequestPermissionsResult(
@NonNull int requestCode,
@NonNull Array<@NonNull String> permissions,
@NonNull Array<@NonNull int> grantResults
)
@NonNull
public void onStateNotSaved()
Hook in to note that fragment state is no longer saved.
@NonNull
public void setEnterSharedElementCallback(@Nullable SharedElementCallback callback)
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 | |
---|---|
@Nullable SharedElementCallback callback |
Used to manipulate shared element transitions on the launched Activity. |
@NonNull
public void setExitSharedElementCallback(@Nullable SharedElementCallback listener)
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 | |
---|---|
@Nullable SharedElementCallback listener |
Used to manipulate shared element transitions on the launching Activity. |
@NonNull
public void startActivityFromFragment(
@NonNull Fragment fragment,
@NonNull Intent intent,
@NonNull int requestCode
)
Called by Fragment.startActivityForResult() to implement its behavior.
Parameters | |
---|---|
@NonNull Fragment fragment |
the Fragment to start the activity from. |
@NonNull Intent intent |
The intent to start. |
@NonNull int requestCode |
The request code to be returned in |
@NonNull
public void startActivityFromFragment(
@NonNull Fragment fragment,
@NonNull Intent intent,
@NonNull int requestCode,
@Nullable Bundle options
)
Called by Fragment.startActivityForResult() to implement its behavior.
Parameters | |
---|---|
@NonNull Fragment fragment |
the Fragment to start the activity from. |
@NonNull Intent intent |
The intent to start. |
@NonNull int requestCode |
The request code to be returned in |
@Nullable Bundle options |
Additional options for how the Activity should be started. See Context#startActivity(Intent, Bundle) for more details. This value may be null. |
@NonNull
public voidstartIntentSenderFromFragment(
@NonNull Fragment fragment,
@NonNull IntentSender intent,
@NonNull int requestCode,
@Nullable Intent fillInIntent,
@NonNull int flagsMask,
@NonNull int flagsValues,
@NonNull int extraFlags,
@Nullable Bundle options
)
Called by Fragment.startIntentSenderForResult() to implement its behavior.
Parameters | |
---|---|
@NonNull Fragment fragment |
the Fragment to start the intent sender from. |
@NonNull IntentSender intent |
The IntentSender to launch. |
@NonNull int requestCode |
The request code to be returned in |
@Nullable Intent fillInIntent |
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. |
@NonNull int flagsMask |
Intent flags in the original IntentSender that you would like to change. |
@NonNull int flagsValues |
Desired values for any bits set in |
@NonNull int extraFlags |
Always set to 0. |
@Nullable Bundle options |
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. |
@NonNull
public 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.
@NonNull
public voidsupportInvalidateOptionsMenu()
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.
@NonNull
public void supportPostponeEnterTransition()
Support library version of postponeEnterTransition that works only on API 21 and later.
@NonNull
public void supportStartPostponedEnterTransition()
Support library version of startPostponedEnterTransition that only works with API 21 and later.
@NonNull
public final voidvalidateRequestPermissionsRequestCode(@NonNull int requestCode)