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

前端 未结 5 840
难免孤独
难免孤独 2020-12-02 11:53

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 t

5条回答
  •  借酒劲吻你
    2020-12-02 12:52

    This can be done with navigation action. Because fragmentA is your start destination, so define an action in fragmentA.

    Note these two fields: app:popUpToInclusive="true" app:popUpTo="@id/fragmentA"

    
    
       
    
        
       
    
       
    
    

    When your MainActivity started, just do the navigation with action id, it will remove fragmentA in the stack, and jump to fragmentB. Seemingly, fragmentB is your start destination.

    if(!isAllSetUp)
    {
      // FragmentB
      navController.navigate(R.id.action_a_to_b)
    }
    

提交回复
热议问题