0

I'm developing an app still in its early stages. I'm learning jetpack navigation as it goes.

In short, I need to create a splashscreen, it would do its stuff (initializing etc..) then navigate to the registration/login flow(not implemented yet) or to the main flow (which uses a BottomNavigationView). So I though the easiest way would be to create a SplashscreenActivity and then navigate to MainActivity.

Only I can't figure out how to navigate from SplashscreenActivity to MainActivity, because findNavController() which I usually use in fragments, for activities requieres the id of the navController which I don't think it makes much sense in this case. Is it even possible to achieve that using the jetpack navigation?

Of course, I think I can always go for the good old startActivity(), but is that the right way to go? Would I just be better with creating a SplashscreenFragment and handle everything in MainActivity?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
jack_the_beast
  • 1,838
  • 4
  • 34
  • 67
  • does this answer your question https://stackoverflow.com/questions/61031383/android-navigation-component-change-root-fragment/61031774#61031774 – Mohammed Alaa Aug 28 '20 at 15:04
  • @MohammedAlaa not really, before disregarding the "activity" approach, I would like to know if it's possible to use it. – jack_the_beast Aug 28 '20 at 15:11
  • yes I think it's possible, but if you are using navigation component they recommend using single activity multiple fragments – Mohammed Alaa Aug 28 '20 at 15:16
  • 1
    if you will go with activity approach check https://stackoverflow.com/questions/50452359/navigation-architecture-component-activities – Mohammed Alaa Aug 28 '20 at 15:22

1 Answers1

0

Seems like the navigation component allow to do this, but it's not really designed for.

So one can either switch to a one-activity architecture or do this:

ActivityNavigator(this)
                    .createDestination()
                    .setIntent(Intent(this, SecondActivity::class.java))
                    .navigate(null, null) 

but digging in what this snippet does, reveal that it's equivalent to startActivity(), so it has no real use.

jack_the_beast
  • 1,838
  • 4
  • 34
  • 67