是否可以获得当前运行的下面多少个回调?
(new AsyncCallback<List<data>>()
{
@Override
public void onFailure(Throwable caught)
{
}
@Override
public void onSuccess(List<PersonalData> result)
{
}
});
答案 0 :(得分:3)
我使用自己的ExtendedAsyncCallback。它允许我在一些回调仍处于活动状态时阻止UI。请注意,它还允许我避免在每个回调中剪切和粘贴onFailure
。
public class ExtendedAsyncCallback<T> implements AsyncCallback<T> {
private static int activeCallbacks;
public ExtendedAsyncCallback() {
// here I block the UI and show a nice spinner
activeCallbacks++;
}
@Override
public void onFailure(Throwable caught) {
activeCallbacks--;
// show an error message depending on exception
}
@Override
public void onSuccess(T result) {
activeCallbacks--;
if (activeCallbacks == 0) {
// here I hide my spinner
}
execute(result);
}
public void execute(T result) {
// I use this method in presenters instead of 'onSuccess'
}
然后你打电话给:
(new ExtendedAsyncCallback<Object>() {
@Override
public void execute(Object result) {
}
});