簡體   English   中英

android改造await方法完成響應之外

[英]android retrofit await method to finish outside of response

我需要運行BroadcastReceiver在后台進行網絡通話,並通過Notificationmanager向用戶顯示通知。 但是,該方法正在同步運行,並在網絡通話結束之前顯示通知。 我如何等待包含改裝Webcall的void方法? 以下是我需要等待的網絡方法。

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());
        }
    });
}

假。 Execute用於同步調用。 無論如何,我想我已經找到了解決方案。 我將在異步任務中使用同步調用。 這樣,我知道它何時在Web方法之外完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM