0

My launcher activity MainActivity hosts a bottom navigation. I want to check if the user is not logged in and then redirect him to LoginFragment. I'm stranded on how to check if there's a signed-in user in the Mainactivity. I'd be glad if you share some insight

Jerry Matera
  • 11
  • 1
  • 4

1 Answers1

0

You can store the user login status in shared preference when user is logged in first time. Please write below this code in the onCreate() method your MainActivity to check whether user is logged in or not at the time of app opening.

val graph = navController.navInflater.inflate(R.navigation.mobile_navigation)

    if (PrefUtils.with(this).getBoolean(PrefKey.KEY_IS_LOGGOD_IN, false)) {

        bottomNavView.visibility = View.VISIBLE

        graph.startDestination = R.id.navigation_home

    } else {

        bottomNavView.visibility = View.GONE
        graph.startDestination = R.id.loginFragment

    }
    navController.graph = graph

Here if a user is already logged in go to home UI otherwise login UI

Tausif
  • 778
  • 1
  • 5
  • 14