0
我需要運行BroadcastReceiver在後臺進行網絡調用並通過通知管理器向用戶顯示通知。但是,該方法正在同步運行,並在webcall完成之前顯示通知。我如何等待包含改進webcall的無效方法? 下面是我需要等待的網絡方法。android改造等待方法在響應之外完成
public static void getFriendList(String id, final ApiInterface api, final MainActivity activity, final boolean isUpdate)
{
Call<List<String>> call = api.getFriendList(ServiceGenerator.API_KEY, id,"friend");
call.enqueue(new Callback<List<String>>() {
@Override
public void onResponse(Call<List<String>> call, Response<List<String>> response) {
try {
List<String> idsList = new ArrayList<>();
for (String idGroup : response.body()) {
idsList.add(idGroup);
}
for (String ids : idsList) {
getPlayerSummaries(ids, api, activity, isUpdate); // another web call
}
} catch(Exception ex) {
System.out.println("TEST----------------------FAILED IN RESPONSE" + ex);
}
}
@Override
public void onFailure(Call<List<String>> call, Throwable t) {
System.out.println("TEST----------------------FAILED IN FAILURE" + t.getMessage());
}
});
}
如果你想異步調用,然後使用call.execute –