private void updateUI(boolean state,String uid){
if(state) {
Toast.makeText(this, "SUCCESSFULL", Toast.LENGTH_SHORT).show();
if(uid != null) {
Log.d(tag,"uid is"+uid);
database= FirebaseDatabase.getInstance();
action_taken_booking = database.getReference().child("Bae").child("Booking list").child(uid).child("Action taken");
action_taken_blocked = database.getReference().child("Bae/Blocked list/" + uid + "/Action taken");
times_blocked = database.getReference().child("Bae/Blocked list/" + uid + "/Times blocked");
Log.d(tag,action_taken_booking.getParent().toString());
action_taken_booking.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
booking_action_taken = dataSnapshot.getValue(boolean.class);
Log.d(tag,"booking_action_taken"+booking_action_taken);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
action_taken_blocked.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
blcoked_action = (Long) dataSnapshot.getValue();
Log.d(tag,"Blocked action"+blcoked_action);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
times_blocked.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
blocked_times = (Long) dataSnapshot.getValue();
Log.d(tag,"TimesBlocked"+blocked_times);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Log.d(tag,"Upddate UI"+blcoked_action+" "+ blocked_times);
blocked_action_taken = (blocked_times - blcoked_action) == 0;
if (booking_action_taken) {
Intent nextActivity = new Intent(SigninActivity.this, HotelActivity.class);
nextActivity.putExtra("uid", uid);
startActivity(nextActivity);
}
}
}
}
我的代码没有从数据库中读取任何内容。事实上,代码没有进入onDataChange方法。此代码是在登录活动中编写的。我使用共享偏好设置使用了自动登录功能。由于有几种方法可以签名,因此我使用了更新ui方法来进行所需的活动。