Add an Up action

Users need an easy way to get back to your app's main screen. To do this, provide an Up button on the app bar for all activities except the main one. When the user selects the Up button, the app navigates to the parent activity.

This page shows you how to add an Up button to an app bar using the Jetpack Navigation component. For a more detailed explanation, see Update UI components with NavigationUI.

Configure your app bar

Configure your app bar using an AppBarConfiguration. From the AppBarConfiguration, you can inform the app bar of your top-level destinations. If the navigation drawer is configured, the drawer menu icon displays on the app bar on top-level destinations. If the navigation drawer isn't configured, the navigation button is hidden on top-level destinations.

In both cases, the Up button displays on all other destinations. Pressing the Up button calls navigateUp().

The following example shows how to configure an app bar using AppBarConfiguration:


  override fun onCreate(savedInstanceState: Bundle?) {
    val navController = findNavController(
    val appBarConfiguration = AppBarConfiguration(
    binding.myToolbar.setupWithNavController(navController, appBarConfiguration)


  protected void onCreate(Bundle savedInstanceState) {
      NavController navController = Navigation.findNavController(this,;

      AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
      NavigationUI.setupWithNavController(binding.myToolbar, navController, appBarConfiguration);