fasdgoc
fasdgoc

Reputation: 69

Application class's onCreate initialize firebase.auth error

public class ApplicationMy extends Application {
    private FirebaseAuth firebaseAuth;
    @Override
    public void onCreate() {
        this.firebaseAuth = FirebaseAuth.getInstance();
    }
}

And, I also added option of manifests like below

<application
    android:name=".ApplicationMy"
    ...
>
...
</application>

In this case above, app is not dead and looks working well, but error-window occurs...

Like Above case, If i do the code like below, It works well perfectly not showing error window.

public class ApplicationMy extends Application {
    private int test;
    @Override
    public void onCreate() {
        this.test = 123;
    }
}

What's the problem?

Upvotes: 0

Views: 1375

Answers (2)

Al Wld
Al Wld

Reputation: 939

You need to call Firebase.setAndroidContext(Context context) before any other call. Try the following:

public class ApplicationMy extends Application {
    private FirebaseAuth firebaseAuth;
    @Override
    public void onCreate() {
        Firebase.setAndroidContext(this);
        this.firebaseAuth = FirebaseAuth.getInstance();
    }
}

Upvotes: 0

Nishant Dubey
Nishant Dubey

Reputation: 2872

I assume doing that in application class is not the right way. Doing same in an activity wouldn't be a problem.

public class MainActivity extends AppCompatActivity {
    private FirebaseAuth firebaseAuth;
    @Override
    public void onCreate() {
       firebaseAuth = FirebaseAuth.getInstance();
    }
}  

This is what I would ask you to do.

Upvotes: 1

Related Questions