package com.nmakademija.nmaakademija;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class BaseActivity extends AppCompatActivity {

    public FirebaseAuth mAuth;
    protected FirebaseAuth.AuthStateListener mAuthListener;

    protected void onUserChange(@Nullable FirebaseUser user) {
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public void onStart() {
        super.onStart();

        if (mAuth == null)
            mAuth = FirebaseAuth.getInstance();
        if (mAuthListener == null)
            mAuthListener = new FirebaseAuth.AuthStateListener() {
                @Override
                public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                    onUserChange(firebaseAuth.getCurrentUser());
                }
            };
        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    public void onStop() {
        super.onStop();
        if (mAuthListener != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }
}


@@ -32,16 +32,42 @@
 emija;%0A%0A
+import android.os.Bundle;%0A
 import a
@@ -858,131 +858,267 @@
    p
-ublic void onStart() %7B%0A        super.onStart();%0A%0A        if (mAuth == null)%0A            mAuth = FirebaseAuth.getInstance();
+rotected void onCreate(@Nullable Bundle savedInstanceState) %7B%0A        super.onCreate(savedInstanceState);%0A%0A        if (mAuth == null)%0A            mAuth = FirebaseAuth.getInstance();%0A    %7D%0A%0A    @Override%0A    protected void onStart() %7B%0A        super.onStart();%0A
 %0A   

fix null pointer exception FirebaseAuth