0

I have a feature module, splash, which has a nav_splash graph and a SplashActivity.

When I navigate to a second feature module, main, which has a nav_main graph and a MainActivity, instead of using MainActivity as host (even in the navigation editor it is appearing as host), it keeps using SplashActivity as host.

So instead of navigating to nav_main graph, now I have to navigate to an activity (MainActivity) to force the use of this activity as host.

Is this intentionally? Or is it a bug?

The first reason to use multiple activities is that they have different themes in the manifest file.

JavierSegoviaCordoba
  • 6,531
  • 9
  • 37
  • 51
  • 1
    Note that you should not be using a splash activity, graph, or anything like that. See the guidance around a [branded launch screen](https://antonioleiva.com/branded-launch-screen/) and [conditional navigation like login and first time user setup](https://developer.android.com/guide/navigation/navigation-conditional). – ianhanniballake Jul 24 '19 at 23:41
  • Thank you for all the information! – JavierSegoviaCordoba Jul 24 '19 at 23:45
  • @ianhanniballake I am having a problem related with Conditional Navigation. Actually, the SplashActivity (and SplashFragment) is the main_fragment of your article, so it is a bridge to navigate to the MainActivity or LoginActivity after checking if the user is logged in. SplashActivity and LoginActivity use FullScreenTheme without a toolbar, MainActivity has an AppTheme with a toolbar. They are activities in the nav_splash graph so when I use popTo, single top and inclusive (like in fragments) to remove the splash screen from the back stack, it is not working. – JavierSegoviaCordoba Jul 25 '19 at 08:52
  • 1
    There should be no redirection only destination when using Navigation. See the [Update UI documentation](https://developer.android.com/guide/navigation/navigation-ui#listen_for_navigation_events) for guidance on hiding Toolbars or other global navigation when on certain destinations (such as your login screen). – ianhanniballake Jul 25 '19 at 16:22
  • Thank you again! The Update UI documentation was the missing piece of the puzzle to avoid having more than 1 activity. – JavierSegoviaCordoba Jul 25 '19 at 19:43

1 Answers1

2

Unless you're specifically navigating to an <activity> destination, you'll stay in the same activity, that is working as intended.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443