非常慢的AsyncTask

时间:2012-06-24 08:04:26

标签: android performance android-asynctask

我创建了一个异步任务,执行请求认为HttpClient并将日期写入数据库。这个AsyncTask工作得非常慢(我在线程和线程中测试这个算法,这非常有效)。如何加速AsyncTask?

我的代码很标准:

    public class GetDialogs extends AsyncTask<String, Void, Boolean> {

        protected void onPreExecute() {

        }

        @Override
        protected void onPostExecute(final Boolean success) {

        }

        protected Boolean doInBackground(final String... args) {

            try {
                DefaultHttpClient client = new DefaultHttpClient();
                DataBaseHelper helper = new DataBaseHelper(mCtx);
                helper.openDataBase();

                int offset = 0;
                int count = 100;

                HttpGet request = new HttpGet();

                String authQuery = "url";

                request.setURI(new URI(authQuery));
                HttpResponse response = client.execute(request);
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        response.getEntity().getContent()));
                StringBuffer resLine = new StringBuffer();
                String inputLine = "";
                while ((inputLine = in.readLine()) != null) {
                    resLine.append(inputLine);
                }
/*here writing to database throught DataBaseHelper*/
} catch(Exception e) {
System.out.println(e.fillInStackTrace());
}
}

0 个答案:

没有答案