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
Asked
Active
Viewed 292 times
0

Jerry Matera
- 11
- 1
- 4
-
1if user == null, do something, else, do something, i'd guess – a_local_nobody Feb 10 '21 at 10:12
-
https://stackoverflow.com/questions/44583834/firebase-how-to-check-if-user-is-logged-in – Usama Altaf Feb 10 '21 at 10:15
1 Answers
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