![](/img/trans.png)
[英]How to check for a specific value exist in the firebase realtime database?
[英]How to check value in realtime database (ON/OFF)
我如何在這段代碼中
@Override
protected void onStart() {
super.onStart();
//if the user is already signed in
//we will close this activity
//and take the user to profile activity
if (mAuth.getCurrentUser() != null) {
finish();
startActivity(new Intent(this, ActivitySplash.class));
}
}
請檢查子項(userId)是否設置為ON / OFF,如果為ON,則運行代碼
if (mAuth.getCurrentUser() != null) {
finish();
startActivity(new Intent(this, ActivitySplash.class));
}
如果關閉,則顯示特定活動。
正如@FrankvanPuffelen所說,您應該花一些時間閱讀文檔,這將有助於您自己編寫代碼,不過我還是在這里為您介紹這些內容。 它應該使事情更清楚。
通過從數據庫正確引用所需的節點,然后使用正確的eventListener
來完成從數據庫的eventListener
。 存在三種eventListeners
, singleValueEventListener
, valueEventListener
和childEventListener
。
詳細了解每個文檔。 此答案還可以幫助您了解childEventListeners
。
要檢索status
節點的值,您必須依次遍歷數據庫父節點,即users
和具有值nfe...
uid
。
所以在代碼中看起來像這樣:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("users").child(uid);
// uid has the value nfe...
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String status = dataSnapshot.child("status").getValue(String.class);
// compare the value of status here and do what you want
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.d(TAG, "onCancelled", databaseError.toException());
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.