当我启动AsyncTask两次时,第二次启动时首次完成

时间:2015-03-21 22:26:22

标签: android android-asynctask

我在AsyncTask中下载文件。当我启动AsyncTask(新的MyAsyncTask.execute())两次,第一次完成时第二次启动,但我希望它们同时执行。

@Override
protected void onPreExecute() {
    super.onPreExecute();
    Log.d("GrowApp", "start download sound");
}

@Override
protected String doInBackground(String... urlS) {
    int count;
    try {
        Log.d("MyLog", "url " + urlS[0].toString());
        URL url = new URL(urlS[0].toString());
        URLConnection conexion = url.openConnection();
        conexion.connect();

        // downlod the file
        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream(soundFilePath);

        byte data[] = new byte[1024];

        output.flush();
        output.close();
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

@Override
protected void onPostExecute(String s) {
    super.onPostExecute(s);
}

0 个答案:

没有答案