Home > Software engineering >  Get boolean value from realtime database Firebase
Get boolean value from realtime database Firebase

Time:01-15

I need to take the value of a boolean variable, but I can't specify that the local variable is a boolean. How can I do that?

var value = dbRef.Child("Values").Child("updateIsReady").GetValueAsync();
if(value)
{
    //something is happening
}

Try to implement my application's update check through a variable in the database that changes when an update is released

CodePudding user response:

You should get the value once its ready in task.IsCompleted:

FirebaseDatabase.DefaultInstance.GetReference("Values")
.GetValueAsync().ContinueWithOnMainThread(task => {

if (task.IsFaulted) {
// Handle the error...
}

else if (task.IsCompleted) {

//get the data here:

//this is snapshot of the reference
DataSnapshot snapshot = task.Result;

//this is your boolean, you get it from the snapshot
bool updateIsReady = snapshot.Child("updateIsReady").Value;

}
});
  • Related