com.google.firebase.database.DatabaseException: Calls to setPersistenceEnabled() must be made before any other usage of FirebaseDatabase instance

前端 未结 8 918
慢半拍i
慢半拍i 2020-11-29 05:15

I am having a problem when I try to setPersistence in fIREBASE,can someone please explain on how to go about it,

protected void onCreate(Bundle savedInstance         


        
相关标签:
8条回答
  • 2020-11-29 05:57

    If you extend a ContentProvider in your app you can call FirebaseDatabase.getInstance().setPersistenceEnabled(true); in your ContentProvider's onCreate() method because this method is called even before the onCreate() method of your launcher activity. This will also be useful when you use TaskStackBuilder in your app to create a synthetic stack of activities to skip some activities and move forward like when you use in app notifications. So when you come back to the launcher activity moving backwards you might have already used FirebaseDatabase instance somewhere in your application and the error you are getting might pop up in this case as well.

    0 讨论(0)
  • 2020-11-29 05:58

    This solution works for me without extends android.app.Application

    private static FirebaseDatabase firebaseDatabase;
    
        if (firebaseDatabase == null) {
            firebaseDatabase=FirebaseDatabase.getInstance();
            firebaseDatabase.setPersistenceEnabled(true);
        }
        /* Do your other stuff  */
    

    OR

    if (savedInstanceState == null) {
       FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    }
    
    0 讨论(0)
提交回复
热议问题