On an Android application which must works offline most of the time I need, when it\'s online, to do some synchronous operations for i.e. :
User myUser = My
Just add this code on onCreate method on your application class. (change the database reference)
Example:
public class MyApplication extendes Application{
@Override
public void onCreate() {
super.onCreate();
DatabaseReference scoresRef = FirebaseDatabase.getInstance().getReference("scores");
scoresRef.keepSynced(true);
}
}
Works well to me.
Reference: https://firebase.google.com/docs/database/android/offline-capabilities