com.google.firebase.database.OnDisconnect Java Examples

The following examples show how to use com.google.firebase.database.OnDisconnect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OfflineActivity.java    From snippets-android with Apache License 2.0 5 votes vote down vote up
private void onDisconnect() {
    // [START rtdb_on_disconnect_set]
    DatabaseReference presenceRef = FirebaseDatabase.getInstance().getReference("disconnectmessage");
    // Write a string when this client loses connection
    presenceRef.onDisconnect().setValue("I disconnected!");
    // [END rtdb_on_disconnect_set]

    // [START rtdb_on_disconnect_remove]
    presenceRef.onDisconnect().removeValue(new DatabaseReference.CompletionListener() {
        @Override
        public void onComplete(DatabaseError error, @NonNull DatabaseReference reference) {
            if (error != null) {
                Log.d(TAG, "could not establish onDisconnect event:" + error.getMessage());
            }
        }
    });
    // [END rtdb_on_disconnect_remove]

    // [START rtdb_on_disconnect_cancel]
    OnDisconnect onDisconnectRef = presenceRef.onDisconnect();
    onDisconnectRef.setValue("I disconnected");
    // ...
    // some time later when we change our minds
    // ...
    onDisconnectRef.cancel();
    // [END rtdb_on_disconnect_cancel]
}
 
Example #2
Source File: FirestackDatabase.java    From react-native-firestack with MIT License 5 votes vote down vote up
@ReactMethod
public void onDisconnectSetObject(final String path, final ReadableMap props, final Callback callback) {
  DatabaseReference ref = this.getDatabaseReferenceAtPath(path);
  Map<String, Object> m = FirestackUtils.recursivelyDeconstructReadableMap(props);

  OnDisconnect od = ref.onDisconnect();
  od.setValue(m, new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
      handleCallback("onDisconnectSetObject", callback, databaseError, databaseReference);
    }
  });
}
 
Example #3
Source File: FirestackDatabase.java    From react-native-firestack with MIT License 5 votes vote down vote up
@ReactMethod
public void onDisconnectSetString(final String path, final String value, final Callback callback) {
  DatabaseReference ref = this.getDatabaseReferenceAtPath(path);

  OnDisconnect od = ref.onDisconnect();
  od.setValue(value, new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
      handleCallback("onDisconnectSetString", callback, databaseError, databaseReference);
    }
  });
}
 
Example #4
Source File: FirestackDatabase.java    From react-native-firestack with MIT License 5 votes vote down vote up
@ReactMethod
public void onDisconnectRemove(final String path, final Callback callback) {
  DatabaseReference ref = this.getDatabaseReferenceAtPath(path);

  OnDisconnect od = ref.onDisconnect();
  od.removeValue(new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
      handleCallback("onDisconnectRemove", callback, databaseError, databaseReference);
    }
  });
}
 
Example #5
Source File: FirestackDatabase.java    From react-native-firestack with MIT License 5 votes vote down vote up
@ReactMethod
public void onDisconnectCancel(final String path, final Callback callback) {
  DatabaseReference ref = this.getDatabaseReferenceAtPath(path);

  OnDisconnect od = ref.onDisconnect();
  od.cancel(new DatabaseReference.CompletionListener() {
    @Override
    public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
      handleCallback("onDisconnectCancel", callback, databaseError, databaseReference);
    }
  });
}