Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Error: Notify user of what file is being downloaded
    primarykey
    data
    text
    <p>I have a code that downloads videos from a URL. I am using AsyncTask. Now, what I want to do is notify the user via progress dialog of what video is being downloaded, or something like "Downloading Video 2 of 10". I am using the following code:</p> <pre><code>//DOWNLOAD VIDEOS private class downloadVideosAsync extends AsyncTask &lt;String, String, String&gt;{ protected void onPreExecute(){ super.onPreExecute(); MyActivity.this.mProgressDialog.setMessage("Downloading Videos..."); } @Override protected String doInBackground(String... strings){ try{ ArrayList&lt;String&gt; VideoNames = VideosM.getVideoNames(); ArrayList&lt;String&gt; VideoUrls = VideosM.getVideoUrls(); File vidFile = null; int videoNamesLenght = VideoNames.size(); int x; for(x = 0; x &lt; videoNamesLenght; x++) { //download video String[] videoName = VideoNames.get(x).split("/"); String currentFile = videoName[0] + "." + videoName[1]; String currentFileURL = VideoUrls.get(x) + VideoNames.get(x); vidFile = new File(Environment.getExternalStorageDirectory() + "/Engagia/Downloads/Videos/", currentFile); if( !vidFile.exists() ){ int curr_vid = x + 1; String ui_msg = "Downloading Videos " + curr_vid + " of " + videoNamesLenght + "..."; MyActivity.this.mProgressDialog.setMessage( ui_msg ); VideosC.downloadVideoFile(currentFile, currentFileURL, vidFile); } } }catch (NullPointerException e){ Log.e(LOG_TAG, e.toString()); }catch(Exception e){ Log.e(LOG_TAG, e.toString()); } return null; } @Override protected void onPostExecute(String lenghtOfFile) { new downloadSlideshowsAsync().execute(); } } </code></pre> <p>The code above give me an error: </p> <p><strong>android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.</strong></p> <p>EDIT:</p> <p>I also tried:</p> <pre><code>runOnUiThread(new Runnable() { public void run() { String ui_msg = "Downloading Videos " + curr_vid + " of " + videoNamesLenght + "..."; Engagia.this.mProgressDialog.setMessage( ui_msg ); Log.v("VideosController.java", ui_msg ); } }); </code></pre> <p>but gives me the same error...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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