0

I'm trying to implement a function retrieve() that will retrieve data from the database, however I cannot stop the execution of the main function, i.e, the function calling retrieve(), until retrieve() finishes execution.

The function I'm trying to implement is:

public void retrieve(final Qu qu) {

        db.collection(COLLECTION).document("someDoc")
            .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                                DocumentSnapshot doc = task.getResult();
                                ques.setQu(q.toObject(Qu.class));
                                }
                            }
                        }
                    }

                }).;
    }

Appreciate the help.

Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
akeira99
  • 33
  • 5
  • The only way to block the call, is going to lead to an "Application Not Responding" dialog for your users. Not a good option. See [my answer here](https://stackoverflow.com/questions/33203379/setting-singleton-property-value-in-firebase-listener). While that is for the Firebase Realtime Database, the same applies here. – Frank van Puffelen Nov 08 '17 at 07:54
  • That worked perfectly. I just realized I didn't comment back! Thank you.@FrankvanPuffelen – akeira99 Nov 14 '17 at 17:49

0 Answers0