0

I use Navigation Component from `Android JetPack. I automatically navigate from first fragment to second every launching the application, but I would like to instead of this skip first fragment if user is logged in. I check it in login fragment then navigate, but maybe there is an option to check it in Main Activity and then skip login fragment and directly open next one?

my logic in viewmodel

class SingleModeAuthViewModel @Inject constructor(
    private val authSharedContext: AuthSharedContext
) : BaseViewModel() {

    fun navigateToViewPagerFragment(
        userEmail: String,
        displayName: String,
        photoUrl: String
    ) {
        navigateTo(
            SingleModeAuthScreenKey(
                userEmail,
                displayName,
                photoUrl
            )
        )
    }

    fun setUserSignedIn(
        isSignedIn: Boolean,
        userEmail: String,
        displayName: String,
        photoUrl: String
    ) {
// here it navigates, but login fragment appears for a second
        if (isSignedIn) navigateToViewPagerFragment(userEmail, displayName, photoUrl)
        authSharedContext.setUserSignedIn(isSignedIn)
    }

    // false all the time
    fun isUserSignedIn(): Boolean {
        return authSharedContext.isUserSignedIn.value
    }
}
Chris
  • 63
  • 6
  • You can set your set your navigation graph (or startDestination) programmatically. Check the answers here: https://stackoverflow.com/questions/51173002/how-to-change-start-destination-of-a-navigation-graph-programmatically – gioravered Sep 29 '22 at 14:33

0 Answers0