Google 致力于为黑人社区推动种族平等。查看具体举措

FragmentActivity

public class FragmentActivity
extends ComponentActivity implements ActivityCompat.OnRequestPermissionsResultCallback

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
         ↳ android.app.Activity
           ↳ androidx.activity.ComponentActivity
             ↳ androidx.fragment.app.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>.

Summary

Inherited constants

Inherited fields

Public constructors

FragmentActivity()

Default constructor for FragmentActivity.

FragmentActivity(int contentLayoutId)

Alternate constructor that can be used to provide a default layout that will be inflated as part of super.onCreate(savedInstanceState).

Public methods

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

Print the Activity's state into the given stream.

FragmentManager getSupportFragmentManager()

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

LoaderManager getSupportLoaderManager()

This method is deprecated. Use LoaderManager.getInstance(this).

void onAttachFragment(Fragment fragment)

This method is deprecated. The responsibility for listening for fragments being attached has been moved to FragmentManager. You can add a listener to this Activity's FragmentManager by calling FragmentManager.addFragmentOnAttachListener(FragmentOnAttachListener) in your constructor to get callbacks when a fragment is attached directly to the activity's FragmentManager.

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)

This method is deprecated. use registerForActivityResult(ActivityResultContract, ActivityResultCallback) passing in a ActivityResultContracts.RequestMultiplePermissions object for the ActivityResultContract and handling the result in the callback.

void onStateNotSaved()

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

void setEnterSharedElementCallback(SharedElementCallback callback)

When ActivityOptions.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 ActivityOptions.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 startActivityFromFragment(Fragment fragment, Intent intent, int requestCode, Bundle options)

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

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

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

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

This method is deprecated. Fragments should use Fragment.registerForActivityResult(ActivityResultContract, ActivityResultCallback) with the ActivityResultContracts.StartIntentSenderForResult contract. This method will still be called when Fragments call the deprecated startIntentSenderForResult() method.

void supportFinishAfterTransition()

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

void supportInvalidateOptionsMenu()

This method is deprecated. Call Activity.invalidateOptionsMenu() directly.

void supportPostponeEnterTransition()

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

void supportStartPostponedEnterTransition()

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

final void validateRequestPermissionsRequestCode(int requestCode)

This method is deprecated. there are no longer any restrictions on permissions requestCodes.

Protected methods

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

This method is deprecated. use registerForActivityResult(ActivityResultContract, ActivityResultCallback) with the appropriate ActivityResultContract and handling the result in the callback.

void onCreate(Bundle savedInstanceState)

If your ComponentActivity is annotated with ContentView, this will call setContentView(int) for you. 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 onStart()

Dispatch onStart() to all fragments.

void onStop()

Dispatch onStop() to all fragments.

Inherited methods

Public constructors