How to bypass the Firebase cache to refresh data (in Android app)?

后端 未结 7 1900
孤街浪徒
孤街浪徒 2020-11-30 21:48

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         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 22:47

    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

提交回复
热议问题