OnDisconnect

public classOnDisconnect


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 callingonDisconnect on a Firebase Database ref.

Summary

Public methods

@NonNullTask<Void>

Cancel any disconnect operations that are queued up at this location

void

Cancel any disconnect operations that are queued up at this location

@NonNullTask<Void>

Remove the value at this location when the client disconnects

void

Remove the value at this location when the client disconnects

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

@NonNullTask<Void>
setValue(@NullableObject value, @NullableString 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).

@NonNullTask<Void>
setValue(@NullableObject 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(
    @NullableObject value,
    @NullableMap priority,
    @NullableDatabaseReference.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(
    @NullableObject value,
    @NullableString priority,
    @NullableDatabaseReference.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(
    @NullableObject value,
    double priority,
    @NullableDatabaseReference.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).

@NonNullTask<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 @NonNullTask<Voidcancel()

Cancel any disconnect operations that are queued up at this location

Returns
@NonNullTask<Void>

TheTask for this operation.

cancel

public void cancel(@NonNullDatabaseReference.CompletionListener listener)

Cancel any disconnect operations that are queued up at this location

Parameters
@NonNullDatabaseReference.CompletionListener listener

A listener that will be triggered once the server has cancelled the operations

removeValue

public @NonNullTask<VoidremoveValue()

Remove the value at this location when the client disconnects

Returns
@NonNullTask<Void>

TheTask for this operation.

removeValue

public void removeValue(@NullableDatabaseReference.CompletionListener listener)

Remove the value at this location when the client disconnects

Parameters
@NullableDatabaseReference.CompletionListener listener

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

setValue

public @NonNullTask<VoidsetValue(@NullableObject 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
@NullableObject value

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

Returns
@NonNullTask<Void>

TheTask for this operation.

setValue

public void setValue(
    @NullableObject value,
    @NullableDatabaseReference.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
@NullableObject value

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

@NullableDatabaseReference.CompletionListener listener

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

setValue

public @NonNullTask<VoidsetValue(@NullableObject value, @NullableString 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
@NullableObject value

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

@NullableString priority

The priority to be set when a disconnect occurs or null to clear the existing priority

Returns
@NonNullTask<Void>

TheTask for this operation.

setValue

public @NonNullTask<VoidsetValue(@NullableObject 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
@NullableObject 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
@NonNullTask<Void>

TheTask for this operation.

setValue

public void setValue(
    @NullableObject value,
    @NullableMap priority,
    @NullableDatabaseReference.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
@NullableObject value

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

@NullableMap priority

The priority to be set when a disconnect occurs

@NullableDatabaseReference.CompletionListener listener

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

setValue

public void setValue(
    @NullableObject value,
    @NullableString priority,
    @NullableDatabaseReference.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
@NullableObject value

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

@NullableString priority

The priority to be set when a disconnect occurs or null to clear the existing priority

@NullableDatabaseReference.CompletionListener listener

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

setValue

public void setValue(
    @NullableObject value,
    double priority,
    @NullableDatabaseReference.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
@NullableObject 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

@NullableDatabaseReference.CompletionListener listener

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

updateChildren

public @NonNullTask<VoidupdateChildren(@NonNullMap<StringObject> update)

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

Parameters
@NonNullMap<StringObject> update

The paths to update, along with their desired values

Returns
@NonNullTask<Void>

TheTask for this operation.

updateChildren

public void updateChildren(
    @NonNullMap<StringObject> update,
    @NullableDatabaseReference.CompletionListener listener
)

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

Parameters
@NonNullMap<StringObject> update

The paths to update, along with their desired values

@NullableDatabaseReference.CompletionListener listener

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

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.