Andrew Lam
Andrew Lam

Reputation: 3804

Where is the right place to put Firebase.getDefaultConfig().setPersistenceEnabled(true) in Android?

I got this error

com.firebase.client.FirebaseException: Modifications to Config objects must occur before they are in use

when I include

Firebase.getDefaultConfig().setPersistenceEnabled(true)

in my launcher activity onCreate() method.

Where is the right place to put the code?

Upvotes: 3

Views: 1171

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599081

I often initially put the lines in my main activity. When I get that error, it's a good time to move it to a better place. :-)

A good place to put this would be in the Application subclass:

public class DemoApplication extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Firebase.setAndroidContext(this);
        Firebase.getDefaultConfig().setPersistenceEnabled(true);
    }
}

Upvotes: 4

Related Questions