FireBase Authentication Auth State Changed
<p>I want to be able to pass an intent to an activity based on if the login state changes for the user</p>

<p>i have to following AuthStateListener within the OnCreate method of the LoginActivity</p>

<p>If the user is logged in then i want them to be forwarded to the MainActivity</p>

<p>However if the user is logged out then they need to goto the LoginActivity</p>

<p>The problem comes when they are signed out, it gets stuck in an infinite loop, constantly firing intent at the LoginActivity. </p>

<p>Is there any way of telling where the user is (which activity) when the auth state changes. That way i could place the signed out intent call within an if statement to check if they are already at the LoginAcitvity, thus preventing the loop</p>

<pre><code>   mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Intent intent = new Intent(getBaseContext(), MainActivity.class);
                //intent.putExtra("EXTRA_SESSION_ID", sessionId);
                startActivity(intent);
                Log.d("LOG_Login", "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                String className = this.getClass().getSimpleName();
                if (!(className == "LoginActivity")) {
                    Intent intent = new Intent(getBaseContext(), LoginActivity.class);
                    //intent.putExtra("EXTRA_SESSION_ID", sessionId);
                    startActivity(intent);
                }

                Log.d("LOG_Login", "onAuthStateChanged:signed_out");
            }
            // ...
        }
    };
</code></pre>