I have used a OnSuccessListener to fetch data from firestore database. I want to start a new Intent after Fetching Data Task has finished it's execution. But the intent will be started before finishing the Task. Is there a way to fix this problem?
db.collection("users/user/driver").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots1) {
if (!queryDocumentSnapshots1.isEmpty()) {
List<DocumentSnapshot> list1 = queryDocumentSnapshots1.getDocuments();
for (final DocumentSnapshot d1 : list1) {
String driverId = d1.getId();
db.collection("users/user/driver").document(driverId).collection("checkpoints").get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots2) {
// Some Code
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
}
dialog.dismiss();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
}
);
Intent intent = new Intent(PassengerRouteSearchActivity.this,PassengerRouteSearch2Activity.class);
intent.putStringArrayListExtra("filteredRoutes",filteredRoutes);
startActivity(intent);
You have to pass the intent in the inner
onSuccess
. Then it will work as you expected..