如何确定所有网络呼叫何时完成?

时间:2017-04-13 14:07:47

标签: java android multithreading okhttp3

我有一个显示进度条onViewCreated的片段。然后,通过 Okhttp REST Api 上异步执行多个网络调用。网络调用通过Okhttp的enqueue方法在后台运行。

//several calls similar to this
okHttpClient.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {

        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            //Response JSOn is parsed here
            //then inserted to SQLite
        }
    });

在每个回调中,解析响应 JSON 并将其插入到 SQLite 表中以进行脱机数据访问。还要检索和缓存图像以供离线使用。

如何从主线程中判断All线程何时完成,以关闭进度条并通知用户?

0 个答案:

没有答案
相关问题