AppCompatActivity


public class AppCompatActivity extends FragmentActivity implements AppCompatCallback, TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider


Base class for activities that wish to use some of the newer platform features on older Android devices. Some of these backported features include:

Note that every activity that extends this class has to be themed with Theme.AppCompat or a theme that extends that theme.

Summary

Public constructors

Default constructor for AppCompatActivity.

@ContentView
AppCompatActivity(@LayoutRes 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
void
boolean
T
<T extends View> findViewById(@IdRes int id)
@NonNull AppCompatDelegate
@Nullable ActionBarDrawerToggle.Delegate
@NonNull MenuInflater
Resources
@Nullable ActionBar

Support library version of getActionBar.

@Nullable Intent

Obtain an android.content.Intent that will launch an explicit target activity specified by sourceActivity's PARENT_ACTIVITY element in the application's manifest.

void
void

{@inheritDoc}

void
void

Support version of onCreateNavigateUpTaskStack.

boolean
onKeyDown(int keyCode, KeyEvent event)
final boolean
onMenuItemSelected(int featureId, @NonNull MenuItem item)
boolean
onMenuOpened(int featureId, Menu menu)

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

void
onPanelClosed(int featureId, @NonNull Menu menu)

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

void

Support version of onPrepareNavigateUpTaskStack.

void

Notifies the activity that a support action mode has finished.

void

Notifies the Activity that a support action mode has been started.

void

This method is deprecated.

Use onContentChanged instead.

boolean

This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar.

@Nullable ActionMode

Called when a support action mode is being started for this window.

void
void
setContentView(@LayoutRes int layoutResID)
void
void
void

Set a Toolbar to act as the androidx.appcompat.app.ActionBar for this Activity window.

void
setSupportProgress(int progress)

This method is deprecated.

Progress bars are no longer provided in AppCompat.

void
setSupportProgressBarIndeterminate(boolean indeterminate)

This method is deprecated.

Progress bars are no longer provided in AppCompat.

void

This method is deprecated.

Progress bars are no longer provided in AppCompat.

void

This method is deprecated.

Progress bars are no longer provided in AppCompat.

void
setTheme(@StyleRes int resId)
@Nullable ActionMode

Start an action mode.

void

This method is deprecated.

Call invalidateOptionsMenu directly.

void

Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag FLAG_ACTIVITY_CLEAR_TOP set by this method, along with any others required for proper up navigation as outlined in the Android Design Guide.

boolean

Enable extended support library window features.

boolean

Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

Protected methods

void
void

Destroy all fragments.

void

Called when the locales have been changed.

void

Called when the night mode has changed.

void
onPostCreate(@Nullable Bundle savedInstanceState)
void

Dispatch onResume() to fragments.

void

Dispatch onStart() to all fragments.

void

Dispatch onStop() to all fragments.

void
onTitleChanged(CharSequence title, int color)

Extension functions

final void
ActivityKt.setupActionBarWithNavController(
    @NonNull AppCompatActivity receiver,
    @NonNull NavController navController,
    @NonNull AppBarConfiguration configuration
)

Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.

final void
ActivityKt.setupActionBarWithNavController(
    @NonNull AppCompatActivity receiver,
    @NonNull NavController navController,
    DrawerLayout drawerLayout
)

Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.

Inherited Constants

From android.app.Activity
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
From android.content.ComponentCallbacks2
static final int
static final int
static final int
static final int
static final int
static final int
static final int
From android.content.Context
static final String
ACCESSIBILITY_SERVICE = "accessibility"
static final String
ACCOUNT_SERVICE = "account"
static final String
ACTIVITY_SERVICE = "activity"
static final String
ALARM_SERVICE = "alarm"
static final String
APPWIDGET_SERVICE = "appwidget"
static final String
APP_OPS_SERVICE = "appops"
static final String
APP_SEARCH_SERVICE = "app_search"
static final String
AUDIO_SERVICE = "audio"
static final String
BATTERY_SERVICE = "batterymanager"
static final int
static final int
static final int
static final int
static final int
static final int
static final int
BIND_EXTERNAL_SERVICE = -2147483648
static final long
BIND_EXTERNAL_SERVICE_LONG = 4611686018427387904
static final int
static final int
static final int
static final int
static final int
static final int
static final String
BIOMETRIC_SERVICE = "biometric"
static final String
BLOB_STORE_SERVICE = "blob_store"
static final String
BLUETOOTH_SERVICE = "bluetooth"
static final String
BUGREPORT_SERVICE = "bugreport"
static final String
CAMERA_SERVICE = "camera"
static final String
CAPTIONING_SERVICE = "captioning"
static final String
CARRIER_CONFIG_SERVICE = "carrier_config"
static final String
CLIPBOARD_SERVICE = "clipboard"
static final String
COMPANION_DEVICE_SERVICE = "companiondevice"
static final String
CONNECTIVITY_DIAGNOSTICS_SERVICE = "connectivity_diagnostics"
static final String
CONNECTIVITY_SERVICE = "connectivity"
static final String
CONSUMER_IR_SERVICE = "consumer_ir"
static final int
static final int
static final int
static final String
CREDENTIAL_SERVICE = "credential"
static final String
CROSS_PROFILE_APPS_SERVICE = "crossprofileapps"
static final int
static final int
static final String
DEVICE_LOCK_SERVICE = "device_lock"
static final String
DEVICE_POLICY_SERVICE = "device_policy"
static final String
DISPLAY_HASH_SERVICE = "display_hash"
static final String
DISPLAY_SERVICE = "display"
static final String
DOMAIN_VERIFICATION_SERVICE = "domain_verification"
static final String
DOWNLOAD_SERVICE = "download"
static final String
DROPBOX_SERVICE = "dropbox"
static final String
EUICC_SERVICE = "euicc"
static final String
FILE_INTEGRITY_SERVICE = "file_integrity"
static final String
FINGERPRINT_SERVICE = "fingerprint"
static final String
GAME_SERVICE = "game"
static final String
GRAMMATICAL_INFLECTION_SERVICE = "grammatical_inflection"
static final String
HARDWARE_PROPERTIES_SERVICE = "hardware_properties"
static final String
HEALTHCONNECT_SERVICE = "healthconnect"
static final String
INPUT_METHOD_SERVICE = "input_method"
static final String
INPUT_SERVICE = "input"
static final String
IPSEC_SERVICE = "ipsec"
static final String
JOB_SCHEDULER_SERVICE = "jobscheduler"
static final String
KEYGUARD_SERVICE = "keyguard"
static final String
LAUNCHER_APPS_SERVICE = "launcherapps"
static final String
LAYOUT_INFLATER_SERVICE = "layout_inflater"
static final String
LOCALE_SERVICE = "locale"
static final String
LOCATION_SERVICE = "location"
static final String
MEDIA_COMMUNICATION_SERVICE = "media_communication"
static final String
MEDIA_METRICS_SERVICE = "media_metrics"
static final String
MEDIA_PROJECTION_SERVICE = "media_projection"
static final String
MEDIA_ROUTER_SERVICE = "media_router"
static final String
MEDIA_SESSION_SERVICE = "media_session"
static final String
MIDI_SERVICE = "midi"
static final int
MODE_APPEND = 32768
static final int
static final int

This field is deprecated.

static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final String
static final String
NFC_SERVICE = "nfc"
static final String
NOTIFICATION_SERVICE = "notification"
static final String
NSD_SERVICE = "servicediscovery"
static final String
OVERLAY_SERVICE = "overlay"
static final String
PEOPLE_SERVICE = "people"
static final String
PERFORMANCE_HINT_SERVICE = "performance_hint"
static final String
POWER_SERVICE = "power"
static final String
PRINT_SERVICE = "print"
static final int
static final int
static final int
static final String
RESTRICTIONS_SERVICE = "restrictions"
static final String
ROLE_SERVICE = "role"
static final String
SEARCH_SERVICE = "search"
static final String
SENSOR_SERVICE = "sensor"
static final String
SHORTCUT_SERVICE = "shortcut"
static final String
STATUS_BAR_SERVICE = "statusbar"
static final String
STORAGE_SERVICE = "storage"
static final String
STORAGE_STATS_SERVICE = "storagestats"
static final String
SYSTEM_HEALTH_SERVICE = "systemhealth"
static final String
TELECOM_SERVICE = "telecom"
static final String
TELEPHONY_IMS_SERVICE = "telephony_ims"
static final String
static final String
TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service"
static final String
TEXT_CLASSIFICATION_SERVICE = "textclassification"
static final String
static final String
TV_INPUT_SERVICE = "tv_input"
static final String
TV_INTERACTIVE_APP_SERVICE = "tv_interactive_app"
static final String
UI_MODE_SERVICE = "uimode"
static final String
USAGE_STATS_SERVICE = "usagestats"
static final String
USB_SERVICE = "usb"
static final String
USER_SERVICE = "user"
static final String
VIBRATOR_MANAGER_SERVICE = "vibrator_manager"
static final String
VIBRATOR_SERVICE = "vibrator"

This field is deprecated.

static final String
VIRTUAL_DEVICE_SERVICE = "virtualdevice"
static final String
VPN_MANAGEMENT_SERVICE = "vpn_management"
static final String
WALLPAPER_SERVICE = "wallpaper"
static final String
WIFI_AWARE_SERVICE = "wifiaware"
static final String
WIFI_P2P_SERVICE = "wifip2p"
static final String
static final String
WIFI_SERVICE = "wifi"
static final String
WINDOW_SERVICE = "window"

Inherited fields

From androidx.activity.ComponentActivity
final ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

Inherited methods

From android.app.Activity
void
void
void
PendingIntent
createPendingResult(int requestCode, Intent data, int flags)
final void
dismissDialog(int id)

This method is deprecated.

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

This method is deprecated.

boolean
void
void
finishActivity(int requestCode)
void
finishActivityFromChild(Activity child, int requestCode)

This method is deprecated.

void
void
void
void

This method is deprecated.

ActionBar
final Application
ComponentName
String
int
ComponentName
Scene
TransitionManager
View
FragmentManager

This method is deprecated.

Intent
Object
String
int
LayoutInflater
LoaderManager

This method is deprecated.

String
int
final MediaController
OnBackInvokedDispatcher
final Activity
Intent
SharedPreferences
getPreferences(int mode)
Uri
int
final SearchEvent
final SplashScreen
Object
int
final CharSequence
final int
VoiceInteractor
final int
Window
WindowManager
boolean
boolean
boolean
final boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final Cursor
managedQuery(
    Uri uri,
    String[] projection,
    String selection,
    String[] selectionArgs,
    String sortOrder
)

This method is deprecated.

boolean
moveTaskToBack(boolean nonRoot)
boolean
navigateUpTo(Intent upIntent)
boolean

This method is deprecated.

void
void
void
onActivityReenter(int resultCode, Intent data)
void
onActivityResult(int requestCode, int resultCode, Intent data)
void
onApplyThemeResource(Resources.Theme theme, int resid, boolean first)
void

This method is deprecated.

void
void

This method is deprecated.

void
onChildTitleChanged(Activity childActivity, CharSequence title)
void
boolean
void
void
onCreate(Bundle savedInstanceState)
void
onCreateContextMenu(
    ContextMenu menu,
    View v,
    ContextMenu.ContextMenuInfo menuInfo
)
CharSequence
Dialog

This method is deprecated.

void
boolean
boolean
onCreatePanelMenu(int featureId, Menu menu)
View
onCreatePanelView(int featureId)
boolean
onCreateThumbnail(Bitmap outBitmap, Canvas canvas)

This method is deprecated.

View
onCreateView(String name, Context context, AttributeSet attrs)
void
void
void
boolean
void
onGetDirectActions(
    CancellationSignal cancellationSignal,
    Consumer<List<DirectAction>> callback
)
boolean
onKeyLongPress(int keyCode, KeyEvent event)
boolean
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
boolean
onKeyShortcut(int keyCode, KeyEvent event)
boolean
onKeyUp(int keyCode, KeyEvent event)
void
void
void
boolean
onMenuItemSelected(int featureId, MenuItem item)
void
onMultiWindowModeChanged(
    boolean isInMultiWindowMode,
    Configuration newConfig
)
boolean
boolean

This method is deprecated.

void
boolean
void
void
onPanelClosed(int featureId, Menu menu)
void
void
onPerformDirectAction(
    String actionId,
    Bundle arguments,
    CancellationSignal cancellationSignal,
    Consumer<Bundle> resultListener
)
void
onPictureInPictureModeChanged(
    boolean isInPictureInPictureMode,
    Configuration newConfig
)
boolean
void
void
void
onPrepareDialog(int id, Dialog dialog)

This method is deprecated.

void
boolean
boolean
onPreparePanel(int featureId, View view, Menu menu)
void
void
void
onProvideKeyboardShortcuts(
    List<KeyboardShortcutGroup> data,
    Menu menu,
    int deviceId
)
Uri
void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)
void
void
onRestoreInstanceState(Bundle savedInstanceState)
void
Object
void
boolean
void
void

This method is deprecated.

void
void
onTopResumedActivityChanged(boolean isTopResumedActivity)
boolean
boolean
void
onTrimMemory(int level)
void
void
void

This method is deprecated.

void
void
onWindowFocusChanged(boolean hasFocus)
ActionMode
void
void
overrideActivityTransition(
    int overrideType,
    int enterAnim,
    int exitAnim
)
void
overridePendingTransition(int enterAnim, int exitAnim)

This method is deprecated.

void
void
void
void
void
void
boolean
final void
removeDialog(int id)

This method is deprecated.

void
DragAndDropPermissions
void
requestFullscreenMode(
    int request,
    OutcomeReceiver<VoidThrowable> approvalCallback
)
final void
requestPermissions(String[] permissions, int requestCode)
final void
boolean
requestVisibleBehind(boolean visible)

This method is deprecated.

final boolean
requestWindowFeature(int featureId)
final T
<T extends View> requireViewById(int id)
final void
void
void
void
setContentView(int layoutResID)
final void
void
void
final void
setFeatureDrawable(int featureId, Drawable drawable)
final void
setFeatureDrawableAlpha(int featureId, int alpha)
final void
setFeatureDrawableResource(int featureId, int resId)
final void
setFeatureDrawableUri(int featureId, Uri uri)
void
setFinishOnTouchOutside(boolean finish)
void
setImmersive(boolean i)
void
setInheritShowWhenLocked(boolean inheritShowWhenLocked)
void
setIntent(Intent newIntent)
void
setLocusContext(LocusId locusId, Bundle bundle)
final void
void
final void
setProgress(int progress)

This method is deprecated.

final void
setProgressBarIndeterminate(boolean indeterminate)

This method is deprecated.

final void

This method is deprecated.

final void
setProgressBarVisibility(boolean visible)

This method is deprecated.

void
setRecentsScreenshotEnabled(boolean enabled)
void
setRequestedOrientation(int requestedOrientation)
final void
setResult(int resultCode)
final void
setSecondaryProgress(int secondaryProgress)

This method is deprecated.

void
setShouldDockBigOverlays(boolean shouldDockBigOverlays)
void
setShowWhenLocked(boolean showWhenLocked)
void
void
void
setTitleColor(int textColor)

This method is deprecated.

boolean
setTranslucent(boolean translucent)
void
setTurnScreenOn(boolean turnScreenOn)
void
setVisible(boolean visible)
final void
setVolumeControlStream(int streamType)
void
setVrModeEnabled(boolean enabled, ComponentName requestedComponent)
boolean
boolean
boolean
boolean
final void
showDialog(int id)

This method is deprecated.

final boolean
showDialog(int id, Bundle args)

This method is deprecated.

void
ActionMode
void
startActivities(Intent[] intents)
void
void
startActivityForResult(Intent intent, int requestCode)
void
startActivityFromChild(Activity child, Intent intent, int requestCode)

This method is deprecated.

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

This method is deprecated.

boolean
startActivityIfNeeded(Intent intent, int requestCode)
void
startIntentSender(
    IntentSender intent,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
void
startIntentSenderForResult(
    IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)
void
startIntentSenderFromChild(
    Activity child,
    IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags
)

This method is deprecated.

void
void
void

This method is deprecated.

boolean
void
void
startSearch(
    String initialQuery,
    boolean selectInitialQuery,
    Bundle appSearchData,
    boolean globalSearch
)
void
void
void

This method is deprecated.

void
takeKeyEvents(boolean get)
void
triggerSearch(String query, Bundle appSearchData)
void
void
void
void
From androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback
abstract void
onRequestPermissionsResult(
    int requestCode,
    @NonNull String[] permissions,
    @NonNull int[] grantResults
)

Callback for the result from requesting permissions.

From androidx.activity.ComponentActivity
void

Adds the given MenuProvider to this MenuHost.

final void

Add a new listener that will get a callback associated with ComponentCallbacks.onConfigurationChanged with the new Configuration.

final void

{@inheritDoc}

final void

Add a new listener that will get a callback associated with Activity.onMultiWindowModeChanged with the new MultiWindowModeChangedInfo.

final void

Add a new listener that will get a callback associated with Activity.onNewIntent with the new Intent.

final void

Add a new listener that will get a callback associated with Activity.onPictureInPictureModeChanged with the new PictureInPictureModeChangedInfo.

final void

Add a new listener that will get a callback associated with ComponentCallbacks2.onTrimMemory with the int representing the level of trimming.

final void

Add a new listener that will get a callback associated with Activity.onUserLeaveHint

final ActivityResultRegistry

Get the ActivityResultRegistry associated with this activity.

CreationExtras
ViewModelProvider.Factory
FullyDrawnReporter

Retrieve the FullyDrawnReporter that should handle the independent parts of the UI that separately report that they are fully drawn.

Object
Lifecycle

{@inheritDoc}

final OnBackPressedDispatcher

Retrieve the OnBackPressedDispatcher that will be triggered when onBackPressed is called.

final SavedStateRegistry
ViewModelStore
void

Sets the view tree owners before setting the content view so that the inflation process and attach listeners will see them already present.

void

Invalidates the android.view.Menu to ensure that what is displayed matches the current internal state of the menu.

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

{@inheritDoc}

void

Called when the activity has detected the user's press of the back key.

void
onCreate(Bundle savedInstanceState)

{@inheritDoc}

boolean
onCreatePanelMenu(int featureId, Menu menu)
boolean
onMenuItemSelected(int featureId, MenuItem item)
void
onMultiWindowModeChanged(boolean isInMultiWindowMode)

{@inheritDoc}

void

{@inheritDoc}

void
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

{@inheritDoc}

boolean
onPreparePanel(int featureId, View view, Menu menu)
void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)

{@inheritDoc}

Object

Use this instead of onRetainNonConfigurationInstance.

final Object

Retain all appropriate non-config state.

void
void
onTrimMemory(int level)

{@inheritDoc}

void

{@inheritDoc}

Context

Get the Context if it is currently available.

final ActivityResultLauncher<I>
<I, O> registerForActivityResult(
    ActivityResultContract<I, O> contract,
    ActivityResultRegistry registry,
    ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

void

Removes the given MenuProvider from this MenuHost.

final void

Remove a previously added listener.

final void

Remove a OnContextAvailableListener previously added via addOnContextAvailableListener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

final void

Remove a previously added listener.

void
void
startActivityForResult(Intent intent, int requestCode)

{@inheritDoc}

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

{@inheritDoc}

From android.content.Context
final int
getColor(int id)
final ColorStateList
final Drawable
getDrawable(int id)
final String
getString(int resId)
final T
<T> getSystemService(Class<T> serviceClass)
final CharSequence
getText(int resId)
final TypedArray
void
void
sendBroadcastWithMultiplePermissions(
    Intent intent,
    String[] receiverPermissions
)
From android.view.ContextThemeWrapper
From android.content.ContextWrapper
boolean
bindIsolatedService(
    Intent service,
    int flags,
    String instanceName,
    Executor executor,
    ServiceConnection conn
)
boolean
bindService(Intent service, ServiceConnection conn, int flags)
boolean
bindServiceAsUser(
    Intent service,
    ServiceConnection conn,
    int flags,
    UserHandle user
)
int
int
checkCallingOrSelfUriPermission(Uri uri, int modeFlags)
int[]
checkCallingOrSelfUriPermissions(List<Uri> uris, int modeFlags)
int
int
checkCallingUriPermission(Uri uri, int modeFlags)
int[]
checkCallingUriPermissions(List<Uri> uris, int modeFlags)
int
checkPermission(String permission, int pid, int uid)
int
int
checkUriPermission(Uri uri, int pid, int uid, int modeFlags)
int[]
checkUriPermissions(List<Uri> uris, int pid, int uid, int modeFlags)
void

This method is deprecated.

Context
Context
Context
Context
Context
createDeviceContext(int deviceId)
Context
Context
Context
createPackageContext(String packageName, int flags)
Context
createWindowContext(int type, Bundle options)
String[]
boolean
boolean
boolean
void
void
enforceCallingOrSelfUriPermission(
    Uri uri,
    int modeFlags,
    String message
)
void
enforceCallingPermission(String permission, String message)
void
enforceCallingUriPermission(Uri uri, int modeFlags, String message)
void
enforcePermission(String permission, int pid, int uid, String message)
void
enforceUriPermission(
    Uri uri,
    int pid,
    int uid,
    int modeFlags,
    String message
)
String[]
Context
ApplicationInfo
AttributionSource
String
Context
File
ClassLoader
File
ContentResolver
File
File
int
File
getDir(String name, int mode)
Display
File
File[]
File
File[]
File[]

This method is deprecated.

File
File
Executor
Looper
File
File
File[]
String
String
PackageManager
String
String
ContextParams
SharedPreferences
getSharedPreferences(String name, int mode)
String
Drawable

This method is deprecated.

int

This method is deprecated.

int

This method is deprecated.

void
grantUriPermission(String toPackage, Uri uri, int modeFlags)
boolean
boolean
boolean
boolean
moveDatabaseFrom(Context sourceContext, String name)
boolean
moveSharedPreferencesFrom(Context sourceContext, String name)
FileInputStream
FileOutputStream
openFileOutput(String name, int mode)
SQLiteDatabase
openOrCreateDatabase(
    String name,
    int mode,
    SQLiteDatabase.CursorFactory factory
)
Drawable

This method is deprecated.

void
Intent
void

This method is deprecated.

void

This method is deprecated.

void
void
revokeUriPermission(Uri uri, int modeFlags)
void
void
void
sendOrderedBroadcast(Intent intent, String receiverPermission)
void
sendOrderedBroadcastAsUser(
    Intent intent,
    UserHandle user,
    String receiverPermission,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)
void

This method is deprecated.

void

This method is deprecated.

void
sendStickyOrderedBroadcast(
    Intent intent,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)

This method is deprecated.

void
sendStickyOrderedBroadcastAsUser(
    Intent intent,
    UserHandle user,
    BroadcastReceiver resultReceiver,
    Handler scheduler,
    int initialCode,
    String initialData,
    Bundle initialExtras
)

This method is deprecated.

void

This method is deprecated.

ComponentName
boolean
startInstrumentation(
    ComponentName className,
    String profileFile,
    Bundle arguments
)
ComponentName
boolean
void
void
void
void
updateServiceGroup(ServiceConnection conn, int group, int importance)
From androidx.fragment.app.FragmentActivity
void
dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)

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).

void
@CallSuper
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

{@inheritDoc}

void

This method is deprecated.

The responsibility for listening for fragments being attached has been moved to FragmentManager.

void
onCreate(@Nullable Bundle savedInstanceState)

{@inheritDoc}

@Nullable View
onCreateView(
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)
@Nullable View
onCreateView(
    @Nullable View parent,
    @NonNull String name,
    @NonNull Context context,
    @NonNull AttributeSet attrs
)
void

Dispatch onPause() to fragments.

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

{@inheritDoc}

void

Dispatch onResume() to fragments.

void

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

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

void

When makeSceneTransitionAnimation was used to start an Activity, callback will be called to handle shared elements on the launched Activity.

void

When makeSceneTransitionAnimation was used to start an Activity, listener will be called to handle shared elements on the launching Activity.

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

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

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

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

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

This method is deprecated.

Fragments should use registerForActivityResult with the StartIntentSenderForResult contract.

void

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

void

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

void

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

final void

This method is deprecated.

there are no longer any restrictions on permissions requestCodes.

From androidx.lifecycle.HasDefaultViewModelProviderFactory
From androidx.lifecycle.LifecycleOwner
abstract Lifecycle
From androidx.core.view.MenuHost
abstract void

Adds the given MenuProvider to this MenuHost.

abstract void
addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner
)

Adds the given MenuProvider to this MenuHost.

abstract void
addMenuProvider(
    @NonNull MenuProvider provider,
    @NonNull LifecycleOwner owner,
    @NonNull Lifecycle.State state
)

Adds the given MenuProvider to this MenuHost once the given LifecycleOwner reaches the given Lifecycle.State.

abstract void

Invalidates the android.view.Menu to ensure that what is displayed matches the current internal state of the menu.

abstract void

Removes the given MenuProvider from this MenuHost.

From androidx.savedstate.SavedStateRegistryOwner
From androidx.lifecycle.ViewModelStoreOwner
From android.view.Window.Callback
void
onPointerCaptureChanged(boolean hasCapture)

Public constructors

AppCompatActivity

Added in 1.1.0
public AppCompatActivity()

Default constructor for AppCompatActivity. All Activities must have a default constructor for API 27 and lower devices or when using the default android.app.AppComponentFactory.

AppCompatActivity

Added in 1.1.0
@ContentView
public AppCompatActivity(@LayoutRes 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.

Public methods

addContentView

public void addContentView(View view, ViewGroup.LayoutParams params)

closeOptionsMenu

public void closeOptionsMenu()

dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent event)

findViewById

public T <T extends View> findViewById(@IdRes int id)

getDelegate

Added in 1.1.0
public @NonNull AppCompatDelegate getDelegate()
Returns
@NonNull AppCompatDelegate

The AppCompatDelegate being used by this Activity.

getDrawerToggleDelegate

Added in 1.7.0
public @Nullable ActionBarDrawerToggle.Delegate getDrawerToggleDelegate()
Returns
@Nullable ActionBarDrawerToggle.Delegate

Delegate to use for ActionBarDrawableToggles, or null if the Activity does not wish to override the default behavior.

getMenuInflater

public @NonNull MenuInflater getMenuInflater()

getResources

public Resources getResources()

getSupportActionBar

Added in 1.1.0
public @Nullable ActionBar getSupportActionBar()

Support library version of getActionBar.

Retrieve a reference to this activity's ActionBar.

Returns
@Nullable ActionBar

The Activity's ActionBar, or null if it does not have one.

getSupportParentActivityIntent

Added in 1.1.0
public @Nullable Intent getSupportParentActivityIntent()

Obtain an android.content.Intent that will launch an explicit target activity specified by sourceActivity's PARENT_ACTIVITY element in the application's manifest. If the device is running Jellybean or newer, the android:parentActivityName attribute will be preferred if it is present.

Returns
@Nullable Intent

a new Intent targeting the defined parent activity of sourceActivity

invalidateOptionsMenu

public void invalidateOptionsMenu()

onConfigurationChanged

public void onConfigurationChanged(@NonNull Configuration newConfig)

{@inheritDoc}

Dispatches this call to all listeners added via addOnConfigurationChangedListener.

onContentChanged

public void onContentChanged()

onCreateSupportNavigateUpTaskStack

Added in 1.1.0
public void onCreateSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder)

Support version of onCreateNavigateUpTaskStack. This method will be called on all platform versions. Define the synthetic task stack that will be generated during Up navigation from a different task.

The default implementation of this method adds the parent chain of this activity as specified in the manifest to the supplied androidx.core.app.TaskStackBuilder. Applications may choose to override this method to construct the desired task stack in a different way.

This method will be invoked by the default implementation of onNavigateUp if shouldUpRecreateTask returns true when supplied with the intent returned by getParentActivityIntent.

Applications that wish to supply extra Intent parameters to the parent stack defined by the manifest should override onPrepareSupportNavigateUpTaskStack.

Parameters
@NonNull TaskStackBuilder builder

An empty TaskStackBuilder - the application should add intents representing the desired task stack

onKeyDown

public boolean onKeyDown(int keyCode, KeyEvent event)

onMenuItemSelected

Added in 1.1.0
public final boolean onMenuItemSelected(int featureId, @NonNull MenuItem item)

onMenuOpened

public boolean onMenuOpened(int featureId, Menu menu)

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

onPanelClosed

public void onPanelClosed(int featureId, @NonNull Menu menu)

Please note: AppCompat uses its own feature id for the action bar: FEATURE_SUPPORT_ACTION_BAR.

onPrepareSupportNavigateUpTaskStack

Added in 1.1.0
public void onPrepareSupportNavigateUpTaskStack(@NonNull TaskStackBuilder builder)

Support version of onPrepareNavigateUpTaskStack. This method will be called on all platform versions. Prepare the synthetic task stack that will be generated during Up navigation from a different task.

This method receives the androidx.core.app.TaskStackBuilder with the constructed series of Intents as generated by onCreateSupportNavigateUpTaskStack. If any extra data should be added to these intents before launching the new task, the application should override this method and add that data here.

Parameters
@NonNull TaskStackBuilder builder

A TaskStackBuilder that has been populated with Intents by onCreateNavigateUpTaskStack.

onSupportActionModeFinished

Added in 1.7.0
@CallSuper
public void onSupportActionModeFinished(@NonNull ActionMode mode)

Notifies the activity that a support action mode has finished. Activity subclasses overriding this method should call the superclass implementation.

Parameters
@NonNull ActionMode mode

The action mode that just finished.

onSupportActionModeStarted

Added in 1.7.0
@CallSuper
public void onSupportActionModeStarted(@NonNull ActionMode mode)

Notifies the Activity that a support action mode has been started. Activity subclasses overriding this method should call the superclass implementation.

Parameters
@NonNull ActionMode mode

The new action mode.

onSupportContentChanged

Added in 1.1.0
Deprecated in 1.1.0
public void onSupportContentChanged()

onSupportNavigateUp

Added in 1.1.0
public boolean onSupportNavigateUp()

This method is called whenever the user chooses to navigate Up within your application's activity hierarchy from the action bar.

If a parent was specified in the manifest for this activity or an activity-alias to it, default Up navigation will be handled automatically. See getSupportParentActivityIntent for how to specify the parent. If any activity along the parent chain requires extra Intent arguments, the Activity subclass should override the method onPrepareSupportNavigateUpTaskStack to supply those arguments.

See Tasks and Back Stack from the developer guide and Navigation from the design guide for more information about navigating within your app.

See the androidx.core.app.TaskStackBuilder class and the Activity methods getSupportParentActivityIntent, supportShouldUpRecreateTask, and supportNavigateUpTo for help implementing custom Up navigation.

Returns
boolean

true if Up navigation completed successfully and this Activity was finished, false otherwise.

onWindowStartingSupportActionMode

Added in 1.7.0
public @Nullable ActionMode onWindowStartingSupportActionMode(@NonNull ActionMode.Callback callback)

Called when a support action mode is being started for this window. Gives the callback an opportunity to handle the action mode in its own unique and beautiful way. If this method returns null the system can choose a way to present the mode or choose not to start the mode at all.

Parameters
@NonNull ActionMode.Callback callback

Callback to control the lifecycle of this action mode

Returns
@Nullable ActionMode

The ActionMode that was started, or null if the system should present it

openOptionsMenu

public void openOptionsMenu()

setContentView

public void setContentView(@LayoutRes int layoutResID)

setContentView

public void setContentView(View view)

setContentView

public void setContentView(View view, ViewGroup.LayoutParams params)

setSupportActionBar

Added in 1.1.0
public void setSupportActionBar(@Nullable Toolbar toolbar)

Set a Toolbar to act as the androidx.appcompat.app.ActionBar for this Activity window.

When set to a non-null value the getActionBar method will return an androidx.appcompat.app.ActionBar object that can be used to control the given toolbar as if it were a traditional window decor action bar. The toolbar's menu will be populated with the Activity's options menu and the navigation button will be wired through the standard home menu select action.

In order to use a Toolbar within the Activity's window content the application must not request the window feature FEATURE_SUPPORT_ACTION_BAR.

Parameters
@Nullable Toolbar toolbar

Toolbar to set as the Activity's action bar, or null to clear it

setSupportProgress

Added in 1.1.0
Deprecated in 1.1.0
public void setSupportProgress(int progress)

setSupportProgressBarIndeterminate

Added in 1.1.0
Deprecated in 1.1.0
public void setSupportProgressBarIndeterminate(boolean indeterminate)

setSupportProgressBarIndeterminateVisibility

Added in 1.1.0
Deprecated in 1.1.0
public void setSupportProgressBarIndeterminateVisibility(boolean visible)

setSupportProgressBarVisibility

Added in 1.1.0
Deprecated in 1.1.0
public void setSupportProgressBarVisibility(boolean visible)

setTheme

public void setTheme(@StyleRes int resId)

startSupportActionMode

Added in 1.1.0
public @Nullable ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback)

Start an action mode.

Parameters
@NonNull ActionMode.Callback callback

Callback that will manage lifecycle events for this context mode

Returns
@Nullable ActionMode

The ContextMode that was started, or null if it was canceled

supportInvalidateOptionsMenu

Added in 1.1.0
public void supportInvalidateOptionsMenu()

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.

supportNavigateUpTo

Added in 1.1.0
public void supportNavigateUpTo(@NonNull Intent upIntent)

Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity in the process. upIntent will have the flag FLAG_ACTIVITY_CLEAR_TOP set by this method, along with any others required for proper up navigation as outlined in the Android Design Guide.

This method should be used when performing up navigation from within the same task as the destination. If up navigation should cross tasks in some cases, see supportShouldUpRecreateTask.

Parameters
@NonNull Intent upIntent

An intent representing the target destination for up navigation

supportRequestWindowFeature

Added in 1.1.0
public boolean supportRequestWindowFeature(int featureId)

Enable extended support library window features.

This is a convenience for calling getWindow().requestFeature().

Parameters
int featureId

The desired feature as defined in android.view.Window or androidx.core.view.WindowCompat.

Returns
boolean

Returns true if the requested feature is supported and now enabled.

supportShouldUpRecreateTask

Added in 1.1.0
public boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent)

Returns true if sourceActivity should recreate the task when navigating 'up' by using targetIntent.

If this method returns false the app can trivially call supportNavigateUpTo using the same parameters to correctly perform up navigation. If this method returns false, the app should synthesize a new task stack by using androidx.core.app.TaskStackBuilder or another similar mechanism to perform up navigation.

Parameters
@NonNull Intent targetIntent

An intent representing the target destination for up navigation

Returns
boolean

true if navigating up should recreate a new task stack, false if the same task should be used for the destination

Protected methods

attachBaseContext

protected void attachBaseContext(Context newBase)

onDestroy

protected void onDestroy()

Destroy all fragments.

onLocalesChanged

Added in 1.6.0
protected void onLocalesChanged(@NonNull LocaleListCompat locales)

Called when the locales have been changed. See applyAppLocales for more information.

Parameters
@NonNull LocaleListCompat locales

the localeListCompat which has been applied

onNightModeChanged

Added in 1.1.0
protected void onNightModeChanged(int mode)

Called when the night mode has changed. See applyDayNight for more information.

Parameters
int mode

the night mode which has been applied

onPostCreate

protected void onPostCreate(@Nullable Bundle savedInstanceState)

onPostResume

protected void onPostResume()

Dispatch onResume() to fragments.

onStart

protected void onStart()

Dispatch onStart() to all fragments.

onStop

protected void onStop()

Dispatch onStop() to all fragments.

onTitleChanged

protected void onTitleChanged(CharSequence title, int color)

Extension functions

ActivityKt.setupActionBarWithNavController

public final void ActivityKt.setupActionBarWithNavController(
    @NonNull AppCompatActivity receiver,
    @NonNull NavController navController,
    @NonNull AppBarConfiguration configuration
)

Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.

By calling this method, the title in the action bar will automatically be updated when the destination changes (assuming there is a valid label).

The AppBarConfiguration you provide controls how the Navigation button is displayed.

You are responsible for calling NavController.navigateUp to handle the Navigation button. Typically this is done in AppCompatActivity.onSupportNavigateUp.

Parameters
@NonNull NavController navController

The NavController whose navigation actions will be reflected in the title of the action bar.

@NonNull AppBarConfiguration configuration

Additional configuration options for customizing the behavior of the ActionBar

ActivityKt.setupActionBarWithNavController

public final void ActivityKt.setupActionBarWithNavController(
    @NonNull AppCompatActivity receiver,
    @NonNull NavController navController,
    DrawerLayout drawerLayout
)

Sets up the ActionBar returned by AppCompatActivity.getSupportActionBar for use with a NavController.

By calling this method, the title in the action bar will automatically be updated when the destination changes (assuming there is a valid label).

The start destination of your navigation graph is considered the only top level destination. On the start destination of your navigation graph, the ActionBar will show the drawer icon if the given drawerLayout is non null. On all other destinations, the ActionBar will show the Up button.

You are responsible for calling NavController.navigateUp to handle the Navigation button. Typically this is done in AppCompatActivity.onSupportNavigateUp.

Parameters
@NonNull NavController navController

The NavController whose navigation actions will be reflected in the title of the action bar.

DrawerLayout drawerLayout

The DrawerLayout that should be toggled from the Navigation button