我在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);
}