私のオンラインサーバに保存されている連絡先をダウンロードし、自分のアクティビティに表示したい。私はサービスを書いており、このダウンロードが行われているonStartCommand
関数からコードスニペットを与えています。サーバからアンドロイド2.1のデータをダウンロード
public int onStartCommand(Intent intent, int flags, int startId)
{
String responseStr = "";
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("action", "get_contact"));
nameValuePairs.add(new BasicNameValuePair("uId", uId + ""));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse = httpClient.execute(httpPost);
BufferedReader in = new BufferedReader (new InputStreamReader(httpResponse.getEntity().getContent()));
responseStr = in.readLine();
in.close();
}
catch (ClientProtocolException e)
{
Log.e("EXCEPTION", "ClientProtocolException");
}
catch (IOException e)
{
Log.e("EXCEPTION", "IOException");
}
this.stopSelf();
return Service.START_STICKY;
}
しかし、このコードの問題は、データをダウンロードするのに時間がかかりすぎるということです。このデータをダウンロードして自分のアクティビティにすばやく表示する方法を教えてください。
ご協力いただきありがとうございます。
お寄せいただきありがとうございます。試してみます。 –