Volley で同期的にリクエストを実行する

Volley は Android のネットワーク処理をいい感じに非同期で行ってくれる。とても便利だけど時々同期的に実行したい時がある。SyncAdapter の中とか。RequestFuture を使って以下のようにすれば非同期呼び出しが終わるまで待つことができる。
    public void someMethod() throws ExecutionException, InterruptedException {
        RequestFuture<String> future = RequestFuture.newFuture();
        StringRequest request = new StringRequest(URL, future, future);
        RequestQueue queue = Volley.newRequestQueue(getContext());
        queue.add(request);
        String result = future.get();// 非同期呼び出しを join する
        // result でなんかする
    }

参考

コメント

  1. The Gambling Room at Borgata, NJ. - Dr. MD
    The 여수 출장마사지 Gambling 사천 출장안마 Room at Borgata, 광양 출장안마 NJ. 3113 영주 출장마사지 Borgata Way, Atlantic City, NJ 08401. 남원 출장샵 Upscale, casual dining.

    返信削除
  2. The Covid outbreak led to a dramatic increase in revenues and downloads of high Casino games, 솔카지노 which continued by way of November 2020. While revenues stay high and haven't but normalized to pre-Covid numbers, downloads dropped considerably in 2021. This report wouldn’t be attainable without the help from our pals at Sensor Tower. Follow us for all of the thrilling things occurring on the earth of Aristocrat Gaming™.

    返信削除

コメントを投稿

このブログの人気の投稿