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

   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.view.ContextThemeWrapper
           ↳ androidx.activity.ComponentActivity

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.

Developer Guides

For information about how to use the action bar, including how to add action items, navigation modes and more, read the Action Bar API guide.


Inherited constants

Inherited fields

Public constructors


Default constructor for AppCompatActivity.

AppCompatActivity(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 addContentView(View view, ViewGroup.LayoutParams params)
void closeOptionsMenu()
boolean dispatchKeyEvent(KeyEvent event)
<T extends View> T findViewById(int id)
AppCompatDelegate getDelegate()
ActionBarDrawerToggle.Delegate getDrawerToggleDelegate()
MenuInflater getMenuInflater()
Resources getResources()
ActionBar getSupportActionBar()

Support library version of Activity.getActionBar().

Intent getSupportParentActivityIntent()

Obtain an Intent that will launch an explicit target activity specified by sourceActivity's NavUtils.PARENT_ACTIVITY <meta-data> element in the application's manifest.

void invalidateOptionsMenu()
void onConfigurationChanged(Configuration newConfig)

Dispatch configuration change to all fragments.

void onContentChanged()
void onCreateSupportNavigateUpTaskStack(TaskStackBuilder builder)

Support version of Activity.onCreateNavigateUpTaskStack(

boolean onKeyDown(int keyCode, KeyEvent event)
final boolean onMenuItemSelected(int featureId, MenuItem item)

Dispatch context and options menu to fragments.

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, Menu menu)

Call onOptionsMenuClosed() on fragments.

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

void onPrepareSupportNavigateUpTaskStack(TaskStackBuilder builder)

Support version of Activity.onPrepareNavigateUpTaskStack(

void onSupportActionModeFinished(ActionMode mode)

Notifies the activity that a support action mode has finished.

void onSupportActionModeStarted(ActionMode mode)

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

void onSupportContentChanged()

This method is deprecated. Use onContentChanged() instead.

boolean onSupportNavigateUp()

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

ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback)

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

void openOptionsMenu()
void setContentView(View view)
void setContentView(int layoutResID)
void setContentView(View view, ViewGroup.LayoutParams params)
void setSupportActionBar(Toolbar toolbar)

Set a