对Android的承诺? [英] Promises for Android?
问题描述
您如何在Android中面对嵌套的回调?例如,在我的应用程序中,我使用Locations API,然后在拥有当前的lat-lng时,向服务器发送HTTP请求.在这种情况下,我有两个嵌套的回调.没那么糟,但是如果我有三个或三个以上怎么办?我已经在这个问题中 阅读了此书,但我想知道是否有类似Android的Promises之类的东西.
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 no 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?
推荐答案
作为Java语言的一部分,已经有一些非常相似的东西,并且受到Android的支持:
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.
顺便说一下,Android尚不支持的Java 8 具有一个名为
By the way, Java 8, which Android does not yet support, has a variant called CompletableFuture that is even closer to a Promise.
这篇关于对Android的承诺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!