Pass data/bundle using navigateUp in Android Navigation Component

前端 未结 6 1124
予麋鹿
予麋鹿 2020-12-14 09:51

I found the question but does not have solution in code

I want to have data when backpress/manual back happens. I am using navigateUp() to go back. How

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 10:28

    To pop destinations when navigating from one destination to another, add an app:popUpTo attribute to the associated element. To navigate from fargment2 to Fragment1 with arguments, specify in the navigation graph the action of the caller fragment and the arguments of the destination fragment :

    
    
        
    
    
    
            
    
    

    In your Fragment2 class, you call your action and pass your argument:

       val action = Fragment2Directions.action2To1("MY_STRING_ARGUMENT")
            findNavController().navigate(action)
    

提交回复
热议问题