Firebase Android - how to tell if node has been synced

前端 未结 1 912
不知归路
不知归路 2020-12-18 06:15

I\'m using Firebase for Android for the chat component of our app. I\'m having trouble figuring out how to reliably implement status updates on each chat message. For exampl

相关标签:
1条回答
  • 2020-12-18 06:29

    From the Firebase documentation on writing data:

    If you'd like to know when your data has been committed, you can add a completion listener. Both setValue() and updateChildren() take an optional completion listener that is called when the write has been committed to the database.

    With this handy code sample:

    ref.setValue("I'm writing data", new Firebase.CompletionListener() {
        @Override
        public void onComplete(FirebaseError firebaseError, Firebase firebase) {
            if (firebaseError != null) {
                System.out.println("Data could not be saved. " + firebaseError.getMessage());
            } else {
                System.out.println("Data saved successfully.");
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题