I am setting offline persistence
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
as described in an earlier post, but the following use case fails:
Sample code:
static{
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
void updateValue(){
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("mydb");
dbRef.keepSynced(true);
dbRef.setValue("123");
}
Note that, if I don't kill the app from memory the caching works:
According to firebase documentation
Transactions are not persisted across app restarts
Even with persistence enabled, transactions are not persisted across app restarts. So you cannot rely on transactions done offline being committed to your Firebase Realtime Database. To provide the best user experience, your app should show that a transaction has not been saved into your Firebase Realtime Database yet, or make sure your app remembers them manually and executes them again after an app restart.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With