0

複数の URL からデータを抽出し、文字列の配列リストとして保存する Android アプリケーションがあります。正常に動作しますが、13 個の URL からデータをフェッチするには、15 ~ 20 秒近くかかります。phonegapを使用して構築された同じアプリでは、同じ一連のURLからデータをフェッチするのに3〜4秒かかります。これが以下のコードです。

        @Override
        protected String doInBackground(String... params) {
            client = new DefaultHttpClient();
            for(int i=0;i<url.size();i++)
            {
                get = new HttpGet(url.get(i));
                try {
                    response = client.execute(get);
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                entity = response.getEntity();
                InputStream is = null;
                try {
                    is = entity.getContent();
                } catch (IllegalStateException e) {         
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(is));
                StringBuffer buffer = new StringBuffer();
                String line = null;
                do {
                    try {
                        line = reader.readLine();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    buffer.append(line);
                } while (line != null);
                String str = buffer.toString();
                param.add(str);             
            }
            return null;
        }

この実行を高速化し、抽出時間を短縮する方法を提案してください。

4

1 に答える 1