Navigation Architecture Component - Activities

前端 未结 3 1506
遥遥无期
遥遥无期 2021-01-31 08:08

I\'ve been following the docs from Navigation Architecture Component to understand how this new navigation system works.

To go/back from one screen to another you need

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-31 08:10

    The navigation graph only exists within a single activity. As per the Migrate to Navigation guide, destinations can be used to start an Activity from within the navigation graph, but once that second activity is started, it is totally separate from the original navigation graph (it could have its own graph or just be a simple activity).

    You can add an Activity destination to your navigation graph via the visual editor (by hitting the + button and then selecting an activity in your project) or by manually adding the XML:

    
    

    Then, you can navigate to that activity (i.e., start the activity) by using it just like any other destination:

    Navigation.findNavController(view).navigate(R.id.secondActivity);
    

提交回复
热议问题