I have tried passing a value between 2 methods by following different solutions on here, but passes null.
The code I am trying to pass:
private void getPrice() {
DatabaseReference dbRequest = FirebaseDatabase.getInstance().getReference(Common
.request_tbl).child(riderId).child("details"); // "Requests"
dbRequest.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
if (child.getKey().equals("price")) {
price = Double.valueOf(child.getValue().toString());
Log.d(TAG, "getPrice: price = " + price);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {}
});
}
Where I am trying to pass the value "price" to:
private void recordData(String riderId) {
getPrice();
Log.d(TAG, "recordData: price = " + price);
...
}
The value of price in getPrice() is what it is supposed to be but when I print out the value in recordData(), the value = null