0
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?

1
  • You should post the stackstrace you find with logcat. Commented Sep 27, 2016 at 21:20

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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();
    }
}

3 Comments

In Activities, if I use firebaseAuth instance generated with ApplcationMy, should i call setAndroidContext each time?
In the Firebase guide, 'In the new SDK, it's no longer necessary to call Firebase.setAndroidContext() so you can remove it from your code.'. here
I solved the problem. FirebaseApp.initializeApp(Context)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.