Reputation: 1590
I currently learning on the new Android Navigation Architecture Component (https://developer.android.com/topic/libraries/architecture/navigation/).
I kind of confuse with its motive and concept, here are my uncertainties:
Example Scenario for Question 2:
Upvotes: 14
Views: 3770
Reputation: 89668
In theory, the Navigation library supports any architecture you might want to use. Out of the box it can handle Activities and Fragments as navigation destinations, but you can plug in your own solution by implementing your own Navigator (as an example, see this article).
However, quoted / paraphrased from the 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.
So Google does recommend having just a couple Activities for your app, because you only really need them to serve as entry points. For example, you can have one that opens from the launcher, and another that's opened by deep links. After that, when your app is started, you can do everything else inside it with Fragments.
To summarize and directly answer your two questions:
The Navigation Architecture Component isn't "designed to eliminate the need to use multiple Activities" per se, but it's something Google recommends doing when you're using it.
You can absolutely still use multiple Activities and multiple Fragments mixed together. You can even use a single Activity with purely View based navigation if you like. It's all up to you. If you find the Navigation library useful in combination with how you architect your app, use it.
The tooling of the library might not be that great for custom destinations (for example, the visual editor will probably only support Activities and Fragments for the time being), but you can use it however you'd like from code.
Upvotes: 10