nishant pathak nishant pathak - 25 days ago 33
Android Question

Firebase realtime database crash when android application used offline

I am using firebase offline database for my android app, in PreferenceScreen and load dynamic config data.

compile 'com.google.firebase:firebase-database:9.8.0'


Using it as:

FirebaseDatabase.getInstance().getReference(fireBaseReference);


I am using it as per tutorial: https://firebase.google.com/docs/database/

App works fine when it is connected, on offline it is crashing with below stack trace

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.nishant.starterkit.mock.
Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)

Answer

Seems like your app has multiple process. Make sure you initialize firebase database only through Context of your application.

    if (!FirebaseApp.getApps(this).isEmpty()) {
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    }

You should initialize firebase DB as mentioned above.