Firebase 断开连接回调
Firebase on disconnect callback
是否可以在断开连接时在 Firebase 中添加一个回调方法,当用户离线时,我可以用它来执行某些操作而不是 Firebase
.onDisconnect().setValue(Boolean.FALSE);
可以在调用 onDisconnect 时更新 firebase 中的值是否可以在此事件上调用用户定义的方法?
当用户断开连接时,可以更新 Firebase 数据库中的值。参见 https://www.firebase.com/docs/android/guide/offline-capabilities.html#section-presence
但是由于这些 onDisconnect()
处理程序 运行 在 Firebase 服务器上,因此 不可能 调用用户定义的函数。如果您想 运行 在 Android 应用程序检测到它与 Firebase 服务器失去连接时添加一些代码,您可以 运行 在线状态系统:https://www.firebase.com/docs/android/guide/offline-capabilities.html#section-connection-state
这对我有用!
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");
}
});
是否可以在断开连接时在 Firebase 中添加一个回调方法,当用户离线时,我可以用它来执行某些操作而不是 Firebase
.onDisconnect().setValue(Boolean.FALSE);
可以在调用 onDisconnect 时更新 firebase 中的值是否可以在此事件上调用用户定义的方法?
当用户断开连接时,可以更新 Firebase 数据库中的值。参见 https://www.firebase.com/docs/android/guide/offline-capabilities.html#section-presence
但是由于这些 onDisconnect()
处理程序 运行 在 Firebase 服务器上,因此 不可能 调用用户定义的函数。如果您想 运行 在 Android 应用程序检测到它与 Firebase 服务器失去连接时添加一些代码,您可以 运行 在线状态系统:https://www.firebase.com/docs/android/guide/offline-capabilities.html#section-connection-state
这对我有用!
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");
}
});