Reputation: 790
Is it possible to add a callback method in Firebase on Disconnect that I can used for to perform some operation rather than Firebase while the user goes offline
.onDisconnect().setValue(Boolean.FALSE);
It is possible to update value in firebase while onDisconnect is called is it possible call a user defined method on this event?
Upvotes: 1
Views: 3565
Reputation: 3006
this works for me!
DBManager.mOnlineRef.child(currentUserID).setValue(currentUserEmail);
DBManager.mOnlineRef.child(currentUserID).onDisconnect().removeValue(new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
Log.e(TAG, "Should be removed");
}
});
Upvotes: 1
Reputation: 599031
It is possible to update a value in the Firebase database when the user disconnects. See https://www.firebase.com/docs/android/guide/offline-capabilities.html#section-presence
But since these onDisconnect()
handlers run on the Firebase servers, it is not possible to call user-defined functions. If you want to run some code in your Android app when it detects that it has lost its connection to the Firebase servers, you can run a presence system: https://www.firebase.com/docs/android/guide/offline-capabilities.html#section-connection-state
Upvotes: 3