Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Asynctask's doInBackground method is called after a long delay
    text
    copied!<p>I have been trying to download videos from a url, I have implemented my downloading method in the doInBackground() of asynctask, but the doInBackground method is taking a lot of time to get called(5-10 mins), I am using another asyntask to download image in the activity from which I am directed to download video activity and its working fine. My onPreExecute method is being called on time, but after that doInBackground takes almost 5-7 minutes to start. I will be really grateful for any help provided. Here is mycode</p> <pre><code>btnDownloadLQ.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { try { new DownloadVideoTask().execute(videoURL); } catch(Exception e) { Log.e("Vidit_TAG","I got an error",e); } } }); private class DownloadVideoTask extends AsyncTask&lt;String, String, String&gt; { @SuppressWarnings("deprecation") @Override protected void onPreExecute() { super.onPreExecute(); showDialog(DIALOG_DOWNLOAD_PROGRESS); } protected String doInBackground(String... urls) { int i=0; try { URL url = new URL (urls[0]); InputStream input = url.openStream(); try { //The sdcard directory e.g. '/sdcard' can be used directly, or //more safely abstracted with getExternalStorageDirectory() String root = Environment.getExternalStorageDirectory().toString(); File storagePath = new File(root + "/vidit"); storagePath.mkdirs(); OutputStream output = new FileOutputStream (new File(storagePath,title+".mp4")); try { byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = input.read(buffer, 0, buffer.length)) &gt;= 0) { output.write(buffer, 0, bytesRead); } } catch(Exception e) { Log.e("Vidit_TAG","I got an error",e); } finally { output.close(); } } catch(Exception e) { Log.e("Vidit_TAG","I got an error",e); } finally { input.close(); //tvTitle.setText("Completed"); } } catch(Exception e) { Log.e("Vidit_TAG","I got an error",e); } return null; } @SuppressWarnings("deprecation") @Override protected void onPostExecute(String unused) { dismissDialog(DIALOG_DOWNLOAD_PROGRESS); alertbox(title); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload