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 9299103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:28:57+00:00 2026-06-18T22:28:57+00:00

i am trying to show the progress dialog in my program when press the

  • 0

i am trying to show the progress dialog in my program when press the refresh button but the application close unexpexted with error in debugger that the thread which one is created ui hierachy can only touch it.

    public class MainActivity extends Activity {
    Handler handler = new Handler();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.refreshView();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public void refreshView(){
        ImageView img = (ImageView) findViewById(R.id.imageView1);
        Bitmap bm = null;
        InputStream is = null;
        BufferedInputStream bis = null;
        try 
        {
            URLConnection conn = new URL("http://technomoot.edu.pk/$Common/Image/Content/ciit_logo.jpg").openConnection();
            conn.connect();
            is = conn.getInputStream();
            bis = new BufferedInputStream(is, 8192);
            bm = BitmapFactory.decodeStream(bis);
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        finally {
            if (bis != null) 
            {
                try 
                {
                    bis.close();
                }
                catch (IOException e) 
                {
                    e.printStackTrace();
                }
            }
            if (is != null) 
            {
                try 
                {
                    is.close();
                }
                catch (IOException e) 
                {
                    e.printStackTrace();
                }
            }
        }
        img.setImageBitmap(bm);
}

    public void onRefresh(View view) {

        final ProgressDialog dialog = ProgressDialog.show(this,"Loading","Loading the image of the Day");
        Thread th = new Thread(){
            public void run(){
                refreshView();
                handler.post(new Runnable(){
                    public void run(){
                        dialog.dismiss();
                    }
                }
                        );
            }

        };th.start();   
    }

}
  • 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-18T22:28:58+00:00Added an answer on June 18, 2026 at 10:28 pm

    You can’t manipulate with UI from worker Thread! It’s prohibited! If you want to update UI just use

    • runOnUiThread()
    • AsyncTask

    So try it like this:

    runOnUiThread(new Runnable() {
    
       @Override
       public void run() {
          // do your work.
    
       }
    });
    

    AsyncTask is more complex, also generic-type that provides some benefits like type control etc. You can look at example here:

    • Android application (performance and more) analysis tools -
      Tutorial
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to show a progress dialog while loading information from the web that
I am trying to show a spinning progress while I load some data, but
I am trying to update progress bar value on my custom ProgressDlg dialog but
I'm trying to show a dialog box that says waiting for GPS fix on
I am trying to dismiss a progress dialog but it doesnt seem to work
I am trying to show a progress dialog from a custom dialog while an
I have a progress dialog I am trying to show when a user clicks
I'm trying to create a pop up dialog progress bar preferably an Indeterminate but
I am trying to show progress dialog using this code pd = ProgressDialog.show(v.getRootView().getContext(), ,
I'm trying to use Progress Dialog with Async task in my Adroid app. But

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.