I want to re-use the following code:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// User is signed in
// Redirect to signed-in flow
} else {
// No user is signed in
// Redirect to login activity
}
But as a beginner with Java and Android, I am not sure in what way to use this code. Should i use it in a separate class and use it in a static way? If so am I correct in the following:
Create separate class called IsUserLoggedIn.java
:
public class IsUserLoggedIn {
public static void isUserLogged() {
if (user != null) {
// User is signed in
// Redirect to signed-in flow
} else {
// No user is signed in
// Redirect to login activity
}
}
}
and in any activity I want to check it, I put the following in onResume
:
IsUserLoggedIn isUserLoggedIn = new IsUserLoggedIn();
isUserLoggedIn.isUserLogged();
Is it correct?