1

In the context of an Android development using Cloud Firestore database, I am writing the method get(int id) : MyDO of my DAO class. Since, in Firestore, all the operations are asynchronous, the use of the return, a MyDO object, must take account of this asynchronous aspect.

A first solution would be the callback. The method get I'm writting could accepts a callback parameter (as a second parameter) in which I would put the code, in the call to get, that uses the object MyDO. However, I don't want it.

I know a bit about promises, or even await/async. Would these notions be useful in this context?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
JarsOfJam-Scheduler
  • 2,809
  • 3
  • 31
  • 70

1 Answers1

2

There are no promises in Java nor await/async, only in Javascript you can find that. More informations here.

In Android, instead of returning a Promise it retruns a Task.

So if you don't want to use a custom callback, you might consider using the following solution:

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193