A. Omar A. Omar - 1 year ago 145
Android Question

"Firebase App named '[DEFAULT]' already exists."

So I was trying to use Firebase in an Android service which is in a seperate process and this error came up while doing:


I wrote this check snippet to overcome the problem:

boolean hasBeenInitialized=false;
List<FirebaseApp> firebaseApps = FirebaseApp.getApps(this);
for(FirebaseApp app : firebaseApps){

if(!hasBeenInitialized) {
FirebaseApp.initializeApp(this, FirebaseOptions.fromResource(this));

// Only then getInstance() will work

And IT WORKS pretty good BUT I'm not sure this is the right way to do it (it's the hardcoded
that bothers me...).

Does anyone knows a proper way to do this ?

Answer Source

You can compare to FirebaseApp.DEFAULT_APP_NAME instead. See the reference docs.