OnDisconnect
public class OnDisconnect
The OnDisconnect class is used to manage operations that will be run on the server when this client disconnects. It can be used to add or remove data based on a client's connection status. It is very useful in applications looking for 'presence' functionality. Instances of this class are obtained by calling onDisconnect on a Firebase Database ref.
Summary
Public methods |
|
|---|---|
@NonNull Task<Void> |
cancel()Cancel any disconnect operations that are queued up at this location |
void |
cancel(@NonNull DatabaseReference.CompletionListener listener)Cancel any disconnect operations that are queued up at this location |
@NonNull Task<Void> |
Remove the value at this location when the client disconnects |
void |
Remove the value at this location when the client disconnects |
@NonNull Task<Void> |
Ensure the data at this location is set to the specified value when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
void |
setValue(Ensure the data at this location is set to the specified value when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
@NonNull Task<Void> |
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
@NonNull Task<Void> |
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
void |
setValue(Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
void |
setValue(Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
void |
setValue(Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). |
@NonNull Task<Void> |
updateChildren(@NonNull Map<String, Object> update)Ensure the data has the specified child values updated when the client is disconnected |
void |
updateChildren(Ensure the data has the specified child values updated when the client is disconnected |
Public methods
cancel
public @NonNull Task<Void> cancel()
Cancel any disconnect operations that are queued up at this location
cancel
public void cancel(@NonNull DatabaseReference.CompletionListener listener)
Cancel any disconnect operations that are queued up at this location
| Parameters | |
|---|---|
@NonNull DatabaseReference.CompletionListener listener |
A listener that will be triggered once the server has cancelled the operations |
removeValue
public @NonNull Task<Void> removeValue()
Remove the value at this location when the client disconnects
removeValue
public void removeValue(@Nullable DatabaseReference.CompletionListener listener)
Remove the value at this location when the client disconnects
| Parameters | |
|---|---|
@Nullable DatabaseReference.CompletionListener listener |
A listener that will be triggered once the server has queued up the operation |
setValue
public @NonNull Task<Void> setValue(@Nullable Object value)
Ensure the data at this location is set to the specified value when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
setValue
public void setValue(
@Nullable Object value,
@Nullable DatabaseReference.CompletionListener listener
)
Ensure the data at this location is set to the specified value when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
| Parameters | |
|---|---|
@Nullable Object value |
The value to be set when a disconnect occurs or null to delete the existing value |
@Nullable DatabaseReference.CompletionListener listener |
A listener that will be triggered once the server has queued up the operation |
setValue
public @NonNull Task<Void> setValue(@Nullable Object value, @Nullable String priority)
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
setValue
public @NonNull Task<Void> setValue(@Nullable Object value, double priority)
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
setValue
public void setValue(
@Nullable Object value,
@Nullable Map priority,
@Nullable DatabaseReference.CompletionListener listener
)
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
| Parameters | |
|---|---|
@Nullable Object value |
The value to be set when a disconnect occurs or null to delete the existing value |
@Nullable Map priority |
The priority to be set when a disconnect occurs |
@Nullable DatabaseReference.CompletionListener listener |
A listener that will be triggered once the server has queued up the operation |
setValue
public void setValue(
@Nullable Object value,
@Nullable String priority,
@Nullable DatabaseReference.CompletionListener listener
)
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
| Parameters | |
|---|---|
@Nullable Object value |
The value to be set when a disconnect occurs or null to delete the existing value |
@Nullable String priority |
The priority to be set when a disconnect occurs or null to clear the existing priority |
@Nullable DatabaseReference.CompletionListener listener |
A listener that will be triggered once the server has queued up the operation |
setValue
public void setValue(
@Nullable Object value,
double priority,
@Nullable DatabaseReference.CompletionListener listener
)
Ensure the data at this location is set to the specified value and priority when the client is disconnected (due to closing the browser, navigating to a new page, or network issues). This method is especially useful for implementing "presence" systems, where a value should be changed or cleared when a user disconnects so that they appear "offline" to other users.
| Parameters | |
|---|---|
@Nullable Object value |
The value to be set when a disconnect occurs or null to delete the existing value |
double priority |
The priority to be set when a disconnect occurs |
@Nullable DatabaseReference.CompletionListener listener |
A listener that will be triggered once the server has queued up the operation |
updateChildren
public @NonNull Task<Void> updateChildren(@NonNull Map<String, Object> update)
Ensure the data has the specified child values updated when the client is disconnected
updateChildren
public void updateChildren(
@NonNull Map<String, Object> update,
@Nullable DatabaseReference.CompletionListener listener
)
Ensure the data has the specified child values updated when the client is disconnected