Reputation: 3169
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?
Upvotes: 1
Views: 186
Reputation: 138999
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:
Upvotes: 2