1
我想在未授權之前從Firebase中刪除數據。問題是,mFirebaseRef.unauth()僅適用於查詢不爲空的情況。但即使查詢爲空,我也需要它。如何檢查Firebase查詢是否爲空
final Firebase pushNotificationRef = new Firebase(Constant.FIREBASE_URL_PUSHNOTIFICATIONS);
final Query queryRef = pushNotificationRef.orderByChild("deviceToken").equalTo(token);
queryRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.exists()) {
Log.e("MyTag", dataSnapshot.getKey());
pushNotificationRef.child(dataSnapshot.getKey()).removeValue();
}
mFirebaseRef.unauth();
}
的'onChildAdded()'方法將只能被稱爲** **如果孩子存在,所以你不能用它來檢測何時不存在孩子。看到這個問題如何檢測:http://stackoverflow.com/questions/34460779/what-happens-if-a-firebase-url-doesnot-exist-and-we-try-to-add-a-listener -to-IT/34463972#34463972 –