I am developing an Android app in which i need to retrieve data from Firestore during app's splash screen and use a particular value from that document snapshot to retrieve another document. For this I need to get the string value out of Firebase's get() function. But when i try this, I am not getting the value of the variable out of the function:
String userCityL;
DocumentReference docRef = firestoreDB.collection("users").document(mail);
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
String userCityL;
if (document.exists()) {
Log.d(TAG, "DocumentSnapshot data: " + document.getData());
userNameL = document.getString("UserName");
userPhoneL = document.getString("UserPhoneNo");
userDegreeL = document.getString("UserDegree");
userSpecialL = document.getString("UserSpecial");
userCityL = document.getString("UserCity");
userProfilePicL = document.getString("downloadUri");
TextView userCity = findViewById(R.id.tvCity);
userCity.setText(userCityL);
//loadNotesList();
//dummy(userCityL);
//loadNotesList(userCityL);
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
Here, nothing is being stored in userCityL
variable.