Android 导航架构组件 - 导航架构组件是否打算仅使用单个 Activity?
Android Navigation Architecture Component - Is Navigation Architecture Component meant to use Single Activity Only?
我目前正在学习新的 Android 导航架构组件 (https://developer.android.com/topic/libraries/architecture/navigation/).
我有点混淆它的动机和概念,这是我不确定的地方:
- Android 导航架构组件 是否旨在消除在单个应用程序中使用多个 Activity 的需要?这意味着,整个应用程序只需要一个 Activity 而所有其他页面将是 Fragment?
- 是否在应用中使用多个 Activity,但同时使用 Android 导航架构组件 来导航 Fragment 实际上违反了 [=22] 的目的=]Android 导航架构组件?
问题 2 的示例场景:
理论上,Navigation 库支持您可能想要使用的任何体系结构。开箱即用,它可以将 Activity 和 Fragment 处理为导航目的地,但您可以通过 implementing your own Navigator (as an example, see this article).
插入您自己的解决方案
但是,引用/释义自 Google I/O talk on Navigation:
What is my Activity actually meant to do?
Right now, some apps are very Activity-heavy, some are Fragment-heavy, or completely in a different system. We're moving towards a model where the Activity is more just an entry point into your app, rather than it being the owner of the content of your app. It's actually just going to store global state, for example global navigation like a navigation drawer or the bottom bar.
所以 Google 建议只为您的应用程序准备几个 Activity,因为您只需要它们作为入口点。例如,您可以让一个从启动器打开,另一个通过深层链接打开。之后,当您的应用程序启动时,您可以使用片段在其中执行其他所有操作。
总结并直接回答你的两个问题:
导航架构组件本身并不是“旨在消除使用多个活动的需要”,但Google建议您在使用它时这样做。
您仍然可以完全混合使用多个 Activity 和多个 Fragment。如果愿意,您甚至可以将单个 Activity 与纯基于视图的导航一起使用。全取决于你。如果您发现导航库与您构建应用程序的方式相结合很有用,请使用它。
库的工具对于自定义目标可能不是很好(例如,可视化编辑器暂时可能只支持 Activities 和 Fragments),但您可以通过代码随意使用它.
我目前正在学习新的 Android 导航架构组件 (https://developer.android.com/topic/libraries/architecture/navigation/).
我有点混淆它的动机和概念,这是我不确定的地方:
- Android 导航架构组件 是否旨在消除在单个应用程序中使用多个 Activity 的需要?这意味着,整个应用程序只需要一个 Activity 而所有其他页面将是 Fragment?
- 是否在应用中使用多个 Activity,但同时使用 Android 导航架构组件 来导航 Fragment 实际上违反了 [=22] 的目的=]Android 导航架构组件?
问题 2 的示例场景:
理论上,Navigation 库支持您可能想要使用的任何体系结构。开箱即用,它可以将 Activity 和 Fragment 处理为导航目的地,但您可以通过 implementing your own Navigator (as an example, see this article).
插入您自己的解决方案但是,引用/释义自 Google I/O talk on Navigation:
What is my Activity actually meant to do?
Right now, some apps are very Activity-heavy, some are Fragment-heavy, or completely in a different system. We're moving towards a model where the Activity is more just an entry point into your app, rather than it being the owner of the content of your app. It's actually just going to store global state, for example global navigation like a navigation drawer or the bottom bar.
所以 Google 建议只为您的应用程序准备几个 Activity,因为您只需要它们作为入口点。例如,您可以让一个从启动器打开,另一个通过深层链接打开。之后,当您的应用程序启动时,您可以使用片段在其中执行其他所有操作。
总结并直接回答你的两个问题:
导航架构组件本身并不是“旨在消除使用多个活动的需要”,但Google建议您在使用它时这样做。
您仍然可以完全混合使用多个 Activity 和多个 Fragment。如果愿意,您甚至可以将单个 Activity 与纯基于视图的导航一起使用。全取决于你。如果您发现导航库与您构建应用程序的方式相结合很有用,请使用它。
库的工具对于自定义目标可能不是很好(例如,可视化编辑器暂时可能只支持 Activities 和 Fragments),但您可以通过代码随意使用它.