I am trying to create share class for accessing firebase authentication between all activities. It also have to handle creating and destroying listener for authentication. So far I wrote this, but I am not sure, that this is best approach - I am afraid of memory leak and issues with ensuring, that class has been set and listener created and destroyed. 

```
public class User {

private static boolean loginPassed = false;
private static String userUid = null;

private static FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;

//MUST BE CALLED FROM ALL ACTIVITIES BEFORE TRY TO ACCESS GETTER/SETTER = SOURCE OF POSSIBLE ISSUES
private static void initUser()
{
    if (!loginPassed)
    {
        //FIREBASE LOGIN
        mAuth = FirebaseAuth.getInstance();
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // User is signed in
                    Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                    userUid = user.getUid();
                    loginPassed = true;
                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                }
                // ...
            }
        };

        //START LISTENER
        mAuth.addAuthStateListener(mAuthListener);

        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Toast.makeText(EmailPasswordActivity.this, R.string.auth_failed,
                                    Toast.LENGTH_SHORT).show();
                        }

                        // ...
                    }
                });
    }
}

public static String getUserUid() {
    return userUid;
}

public static void setUserUid(String userUid) {
    User.userUid = userUid;
}

//HOW TO STOP LISTENER AFTER USER CLOSE ALL ACTIVITIES
private static void stopListener()
{
    mAuth.removeAuthStateListener(mAuthListener);
}

}

```