Android firebase persistence

3

I'm doing an android application with firebase, but I want to add the option to work offline, I read it with

FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

but I do not know how to implement it since I'm getting the following error:

  

E / AndroidRuntime: FATAL EXCEPTION: main Process:   com.example.gabo.company, PID: 20190   com.google.firebase.database.DatabaseException: Calls to   setPersistenceEnabled () must be made before any other usage of   FirebaseDatabase instance. at   com.google.firebase.database.FirebaseDatabase.zzsc (Unknown Source) at   com.google.firebase.database.FirebaseDatabase.setPersistence Enabled (Unknown   Source) at   com.example.gabo.empresa.Vistas.Vista1 $ 6.onClick (Vista1.java: 335)

Will someone have an example of how that is done?

    
asked by GabsUchiha 28.11.2016 в 21:59
source

1 answer

3

If you already have an application that queries your database, if you enable this option your application would work offline since it makes a copy on disk.

FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

Try offline and the access to data would be done from disk!.

It is important to indicate that the persistence of the disk must be enabled before other calls to the database are made.

link

otherwise you can get this error:

  

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

    
answered by 28.11.2016 / 22:11
source