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 any disconnect operations that are queued up at this location

void

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

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>
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).

@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).

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).

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).

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).

@NonNull Task<Void>

Ensure the data has the specified child values updated when the client is disconnected

void

Ensure the data has the specified child values updated when the client is disconnected

Public methods

cancel

public @NonNull Task<Voidcancel()

Cancel any disconnect operations that are queued up at this location

Returns
@NonNull Task<Void>

The Task for this operation.

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<VoidremoveValue()

Remove the value at this location when the client disconnects

Returns
@NonNull Task<Void>

The Task for this operation.

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<VoidsetValue(@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.

Parameters
@Nullable Object value

The value to be set when a disconnect occurs or null to delete the existing value

Returns
@NonNull Task<Void>

The Task for this operation.

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<VoidsetValue(@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.

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

Returns
@NonNull Task<Void>

The Task for this operation.

setValue

public @NonNull Task<VoidsetValue(@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.

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

Returns
@NonNull Task<Void>

The Task for this operation.

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<VoidupdateChildren(@NonNull Map<StringObject> update)

Ensure the data has the specified child values updated when the client is disconnected

Parameters
@NonNull Map<StringObject> update

The paths to update, along with their desired values

Returns
@NonNull Task<Void>

The Task for this operation.

updateChildren

public void updateChildren(
    @NonNull Map<StringObject> update,
    @Nullable DatabaseReference.CompletionListener listener
)

Ensure the data has the specified child values updated when the client is disconnected

Parameters
@NonNull Map<StringObject> update

The paths to update, along with their desired values

@Nullable DatabaseReference.CompletionListener listener

A listener that will be triggered once the server has queued up the operation