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

  • Home
  • SEARCH
  • 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 9184969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:10:54+00:00 2026-06-17T19:10:54+00:00

I have been getting help to create a progress bar for my Android application.

  • 0

I have been getting help to create a progress bar for my Android application. Lots of help here! I’m having an issue though that I am having a hard time fixing. I have a progress bar shown while the application attempts to download files from a networked computer. This works perfectly fine, however I need to update my UI incase an error occurs. I can’t update the UI inside the thread and I want to update the UI from getRaceResultsHandler. Unfortunately it executes that code prior to the thread being completed. I have tried a few things with no luck. I have a code sample with my comments below if anyone can help.

public void getRaceResultsHandler (View view) {

       dialog = new ProgressDialog(this);
       dialog.setCancelable(true);
       dialog.setMessage("Attempting to transfer race files. Please wait...");
       // Set progress style to spinner
       dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
       // display the progressbar
       dialog.show();

       // create a thread for downloading the files

       Thread background = new Thread (new Runnable() {
           public void run() {

                   //The Code here to execute the file download from the networked computer....

                  //Dismiss the progress bar because the download is either completed or failed...
                  dialog.dismiss();                         
           }        
        });
        // start the background thread
        background.start();


              //All Other Code Goes here to update the UI. Shows either an error message or a success based on the results of the download.
//My problem is that this code executes before the background thread is completed. I need it to wait until the thread is completed. 

}
  • 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-06-17T19:10:56+00:00Added an answer on June 17, 2026 at 7:10 pm

    Try to dismiss that dialog using Handler

    Handler h = new Handler(); // Create this object in UI Thread
    
    
    
    Thread background = new Thread (new Runnable() {
       public void run() {
         h.post(new Runnable()
         {
    
           public void run()
           {
             dialog.dismiss();
           }
    
         };
       });
    

    You should use AsyncTask instead of normal Thread

    AsyncTask<Void,Void,Void> aTask = new AsyncTask<Void,Void,Void>()
    {
    
      @Override
      public void onPreExecute()
      {
          // Setup some UI Objects
      }
      @Override
      public void onPostExecute(Void result)
      {
         dialog.dismiss();
    
      }
    
      @Override
      protected Void doInBackground(Void...params)
      {
         // your download stuff
         publishProgress(object) // <-- if you want to update the progress of your download task
      }
    
    
    });
    

    Note: Didn’t try my own, have no IDE here in my friend’s laptop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having a lot of trouble getting cocotron to create a simple
I've taken a screenshot of the compiler inconsistencies that I have been getting when
I have been working on getting my OSGi application to run outside eclipse. It
I've got a table that people have been inserting into getting the primary key
I keep getting errors that my functions have been defined multiple times. Of course
I have been getting help on Stack Overflow over the last 4 days. I
I have been asked to create a console application which polls an active Directory.
I have been getting an invalid character! on what looks like the £ sign
On several of my adsense running sites, I have been getting the following errors:
I have been working on getting this seat mapping chart for a while and

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.