Questions tagged [android-navigation]

For questions about navigation within and between Android apps. Examples include navigating between activities/fragments, up/back behavior, task stacks, and Intent flags that affect navigation behavior.

Consistent navigation is an essential component of the overall user experience. Few things frustrate users more than basic navigation that behaves in inconsistent and unexpected ways.

Android 3.0 introduced significant changes to the global navigation behavior. Thoughtfully following the guidelines for Back and Up will make your app's navigation predictable and reliable for your users.

Android 2.3 and earlier relied upon the system Back button for supporting navigation within an app. With the introduction of action bars in Android 3.0, a second navigation mechanism appeared: the Up button, consisting of the app icon and a left-point caret.

See also the official documentation about this topic.

1192 questions
10
votes
4 answers

Android clear backstack when leaving item tab BottomNavigation

I am using the last navigation library (version 2.4.0) which include multiple backstacks with a bottom navigation view. The default behavior is that each backstack is saved when user go back to a tab. I want to clear a backstack when the user leave…
10
votes
1 answer

Why use "sealed class" and make object in Navigation? (Kotlin Jetpack Compose)

I've heard the most popular way to define screen and route is to use sealed class But I can't understand intuitively that way. first is Why use sealed class. there are other classes including just the default class. The second is Why use object in…
Suee97
  • 627
  • 1
  • 6
  • 13
10
votes
1 answer

viewModelScope.launch does not work for second time

I have 2 fragments, FragmentA contains a list of starwar characters whereas FragmentB contains details of that character. I am using viewModelScope.launch in my fragments to fetch details for a character. Below is my ViewModel @HiltViewModel class…
10
votes
5 answers

Hide Toolbar back arrow with NavigationComponent and BottomNavigationView

I'm in the process of implementing NavigationComponent coupled with a BottomNavigationView and I am noticing that the back arrow is shown in the toolbar for all fragment destinations except the one specified as the startDestination in my navigation…
10
votes
3 answers

how to remove default animation transition when using navigation component in Android?

I am using Navigation component, and I have a bottom navigation view in the main activity. when I tap the tab in that bottom navigation view, it seems that there is a fade in animation when the fragment appear. I don't think I manually set the…
10
votes
1 answer

How to return to the root of a navigation graph?

How can I return to the root Fragment using the NavController? I tried navController.popBackStack(navController.graph.startDestination, false) but it did not work. This did work: navController.navigate(navController.graph.startDestination,…
artkoenig
  • 7,117
  • 2
  • 40
  • 61
10
votes
3 answers

Is it possible to change up button icon in Navigation Component?

I would like to change up button icon in ActionBar that is working with Navigation Component. I've tried several options like: supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_left_blue_24dp) in MainAcitivty or…
10
votes
3 answers

How to get the ID of Toolbar's Navigation Button?

I have an Activity which implements OnClickListener, and I am handling onClick event as below code: void onClick(View v) { final int id = v.getId(); switch (id) { case R.id.xxx: break; } } and now I have a Toolbar also,…
SDJSK
  • 1,292
  • 17
  • 24
10
votes
2 answers

How to combine Navigation Drawer and Spinner [like in Google+ App]

I need your advice. In Google+ App for Android, there are two elements, that I don't know how to put together. One is "Navigation Drawer" and second is "Action Bar Navigation Spinner". Do you know how these two elements put together? Thank you very…
9
votes
6 answers

Android clear backstack after reselecting Bottom Navigation tab

Using the newest Navigation Component with the BottomNavigationView, the NavController now saves and restores the states of tabs by default: As part of this change, the NavigationUI methods of onNavDestinationSelected(),…
9
votes
2 answers

Jetpack Compose. Navigation IllegalStateException

Getting this exception when I quickly switch between destinations (i.e. Bottom navigation: HomeScreen -> SettingsScreen -> HomeScreen). Navigation is implemented according to the example in the documentation and sampleApp. Perhaps this is a Jetpack…
9
votes
2 answers

Class 'action' is not abstract and does not implement abstract member public abstract val actionId: Int defined in androidx.navigation.NavDirections

I used version 2.4.0-alpha04 to conveniently use multi-backstack of navigation. (develop docs) But I got the following error: Class 'ActionDialogToWriteRoutine' is not abstract and does not implement abstract member public abstract val actionId: Int…
ybybyb
  • 1,385
  • 1
  • 12
  • 33
9
votes
3 answers

Navigation Component: how to navigate from activity to a fragment

I want to navigate on click FAB in (activity) to New fragment 1. in my code fab button in the main activity common for all pages. could anyone guide me? activity.xml
9
votes
1 answer

Fragments not added to backstack using Navigation Components

Information: I'm programmatically inserting a NavHostFragment for each feature of the app. Each NavHostFragment has it's own Navigation Graph. Dagger is providing them by using a FragmentFactory specific to each feature. It's a Single Activity…
9
votes
1 answer

Defining a NavHostFragment inside another fragment

I have a fragment that I define a NavHostFragment inside it like this: