Search code examples
androidpromise

Promises for Android?


How do you face nested callbacks in Android? For example, in my app, I use Locations API and then, when I have the current lat-lng, I do an HTTP request to my server. In this situation, I have two nested callbacks. It's not so bad, but what if I had three or more? I've read about it in this question, but I wonder if there are something like Promises for Android.

All I've found is this. Someone knows more about the subject?


Solution

  • There is something pretty similar already available as part of the Java language, and supported by Android: java.util.concurrent.Future. Perhaps it is good enough for your needs.

    By the way, Java 8, which Android does not yet support, has a variant called CompletableFuture that is even closer to a Promise.