Questions tagged [android-navigation-graph]

303 questions
95
votes
5 answers

Is it possible to set startDestination conditionally using Android Navigation Architecture Component(Android Jetpack)?

I am using Navigation from Android Jetpack to navigate between screens. Now I want to set startDestination dynamically. I have an Activity named MainActivity And two Fragments, FragmentA & FragmentB. var isAllSetUp : Boolean = // It is dynamic and…
38
votes
4 answers

Navigation Component prevent to recreate fragment on back press

I'm using the Jetpack Navigation Component in my project with a single activity and some fragments. I have a fragment with a list that fills from server side. I call getDataFromServer on the onViewCreated method then, when a user clicks on an item,…
25
votes
4 answers

Jetpack Compose Navigation - pass argument to startDestination

The app I'm building uses compose navigation with routes. The challenge is that the start destination is dynamic. Here is a minimal example: class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { …
25
votes
5 answers

Android Navigation Instrumentation test throws Method addObserver must be called on the main thread

I have two Fragments, one being a home fragment in my graph. The User will be navigated to the second fragment upon clicking a button. It works as expected by navigating the user to the second fragment and displaying the text. So the graph is…
The_Martian
  • 3,684
  • 5
  • 33
  • 61
20
votes
2 answers

Why onViewCreated is called twice in android app using navigation components

I have a simple application with one activity and around 4 fragments. I am using android navigation components. Starting from my splash fragment to next fragments every time fragment is changed, OnCreateview and onViewCreated is called twice, Once…
20
votes
2 answers

Pass arguments safely to nested graph with Navigation Component

I'm using Android Jetpack Navigation Component. I have a nested nav graph with id, say R.id.nested_graph The first Fragment of the nested graph receives one parameter.
GaRRaPeTa
  • 5,459
  • 4
  • 37
  • 61
18
votes
6 answers
16
votes
4 answers

Handle Toolbar back button with Navigation component

I'm following single activity approach. I have navigation toolbar, whenever i go to other screens (fragments) instead of hamburger icon i will have back arrow. What i want to achieve is, pop my current fragment using action on pressing toolbar back…
Shahal
  • 1,008
  • 1
  • 11
  • 29
13
votes
4 answers

by navGraphViewModels creates java.lang.IllegalArgumentException: No destination with ID is on the NavController's back stack

When a configuration change happens and my Activity and Fragment are recreated because of it, my nav Graph scoped ViewModel is unavailable while the Fragments have already been created again. It seems like the Fragment gets recreated, before the…
13
votes
1 answer

passing ArrayList as argument in safeArgs

I'm trying to pass an ArrayList as an argument while using safeArgs. But when I select ArrayList from the list of serializable and build, it is throwing me these exceptions One type argument expected for class ArrayList One type…
13
votes
1 answer

NavigationComponent navigation within a BottomSheetDialogFragment

Can Android's Navigation Component be used for navigation WITHIN a BottomSheet (i.e. replacing/adding fragments within a single bottom sheet)? I know how to launch a BottomSheetDialogFragment using the tag within a Navigation Graph. For…
12
votes
3 answers

Accessing graph-scoped ViewModel of child NavHostFragment using by navGraphViewModels

I am using the Navigation Component of Android Jetpack (2.2.0-alpha01). I wish to use a child NavHostFragment nested inside my main NavHostFragment, equipped with its own child nav graph. Please view the following image for context: The child nav…
10
votes
9 answers

exception: View does not have a navController set

in the fragment which i made it host in the tag fragment in activity when i use navController = Navigation.findNAvController(view) the app crashes by the error: View does not have a navController set. this is nav_graph:
9
votes
1 answer

Is it possible use different navigation graph with different flavours

I have an Android project with three flavour_a , flavour_b and flavour_c. flavour_a and flavour_b using the same navigation graph. For flavour_c workflow is different means only need to use a subset of fragments. Is it possible to use a different…
CLIFFORD P Y
  • 16,974
  • 6
  • 30
  • 45
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…
1
2 3
20 21