Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7585385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:09:47+00:00 2026-05-30T19:09:47+00:00

I have a code that downloads videos from a URL. I am using AsyncTask.

  • 0

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:

//DOWNLOAD VIDEOS
private class downloadVideosAsync extends AsyncTask <String, String, String>{

    protected void onPreExecute(){
        super.onPreExecute();
        MyActivity.this.mProgressDialog.setMessage("Downloading Videos...");
    }

    @Override
    protected String doInBackground(String... strings){
        try{

            ArrayList<String> VideoNames = VideosM.getVideoNames();
            ArrayList<String> VideoUrls = VideosM.getVideoUrls();

            File vidFile = null;
            int videoNamesLenght = VideoNames.size();
            int x;

            for(x = 0; x < 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();
    }
}

The code above give me an error:

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

EDIT:

I also tried:

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 );

    }
});

but gives me the same error…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:09:48+00:00Added an answer on May 30, 2026 at 7:09 pm

    Only a special thread, often called the “UI thread”, can modify UI elements. You can have specific code run on the UI thread by running things inside the runOnUiThread function that’s part of Activity class. For example:

    runOnUiThread(new Runnable() {
        public void run() {
        // ...
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that downloads a video using AsyncTask. //DOWNLOAD VIDEOS private
I have some code that downloads an image from a remote server $data =
I have the following code which downloads video content: WebRequest wreq = (HttpWebRequest)WebRequest.Create(url); using
I have some code that downloads a plist from a web server and stores
I have code that I want to look like this: List<Type> Os; ... foreach
I have code that I want to compile on all unix systems, but if
I have a code that downloads and reads text files, but it returns IOException
So I have working code that animates a BG image via a plugin. This
i have a video app which downloads and save many videos using NSURLConnection. I
I have code that downloads a set of data (item and value) paired. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.