I have string variable named customerId that is initialized to be empty until my getCustomerID method should populate it. But the datasnapshot for some reason is not populating it. Here is the how the string is initialized below
private String customerID = " ";
Here is the method below
public void getAssignedCustomer() {
String driverId = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference assignedCustomerRef =FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(driverId).child("customerRideId");
assignedCustomerRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
customerID= dataSnapshot.getValue().toString();
getAssignedCustomerLocation();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
The datasnapshot should populate the string variable because there is an acdtual value in it. Below is how a snippet of my firebasedatabase
"sfdqfkoxYjXB2YRDTfIaezWgkBd2":{
"customerRideId":"pUa4kMRMFIMEqZFYQ31w9eOpVhB3"
},
As you cacn see customerRideId actually has a value in it