fasdgoc fasdgoc - 2 months ago 17
Android Question

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?

Answer

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.