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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:25:10+00:00 2026-06-05T06:25:10+00:00

This is the handler, in the main Thread, which shows and dismisses a progress

  • 0

This is the handler, in the main Thread, which shows and dismisses a progress dialog.

public static final int SHOW = 0;
public static final int DISMISS = 1;
public Handler pdHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        Log.i(TAG, "+ handleMessage(msg:" + msg + ")");
        switch(msg.what) {
        case SHOW:
            pd = ProgressDialog.show(LogViewer.this, "", getText(R.string.loading_msg), true);
            break;
        case DISMISS:
            if(pd != null) {
                pd.dismiss();
                pd = null;
            }
            break;
        }
    }
};

The message to show the progress is:

        pdHandler.sendMessage(pdHandler.obtainMessage(SHOW));

The message to dismiss it is:

        pdHandler.sendMessage(pdHandler.obtainMessage(DISMISS));

It works well when I call it before I start an AsyncTask, the AsyncTask onPostExecute() dismisses it.

But when it runs within a runnable (runOnUiThread), the dialog does not show. Examining the
pd variable on the debugger, it shows that is is created, it is running and it is visible, but in practice it is not visible.

Any suggestion?

UPDATE:
I did the obvious test I should have done in the first place. I commented the DISMISS message. And the progress dialog did show up. It appeared too late, after the runnable was finished.
I undestand now that the DISMISS message did dismiss the not-yet-visible ProgressDialog, that’s why I did not see it.
The question becomes now: I need the ProgressDialog to show BEFORE the runnable code is executed. And it is not so straight forward. My call hierarchy is like this:

onScrollEventChanged
    --> runOnUiThread ( 
        --> checkScrollLimits
            --> if need to scroll
                 show ProgressDialog "Loading"
                 get new data into table
                 dismiss ProgressDIalog
    )

I tried something like this:

onScrollEventChanged
    --> checkScrollLimits
        --> if need to scroll
             show ProgressDialog "Loading"
             --> runOnUiThread ( 
                 get new data into table
                 dismiss ProgressDIalog
             )

But still the dismiss message got there before the ProgressDialog could show.

According to Logcat there is a five second interval between the arrival of the SHOW message and the arrival of the DISMISS message.

UPDATE II:
I though I will use the isShowing() method of ProgressDIalog

pd = ProgressDialog.show(...)
while(!pd.isShowing());

But it does not help at all, it returns true even if the dialog is not showing yet.

  • 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-05T06:25:12+00:00Added an answer on June 5, 2026 at 6:25 am

    I made it work by turning the code into AsyncTask and using try/catch blocks.

    See my answer in this post

    I am not sure if AsyncTask is necessary, but after I had it, the try/catch block made the difference.

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

Sidebar

Related Questions

I'm getting this error: Uncaught handler: thread main exiting due to uncaught exception java.lang.VerifyError
I have a Handler class that looks like this: class Handler{ public $group; public
I have this code for an event handler: rbM.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton
I am writing event based android application in which I start main thread which
I have a ListView on main activity, which shows a Contact picture on the
I have this code to show an AlertDialog when taping on a marker: public
I want to ask,i tried to call webapp.RequestHandler ,but this handler didn't called: this
On document ready I attach this event handler to all elements with class bubbleItemOff.
I add an event handler to every AppointmentItem 's send event. This event handler
I have a protocol in Objective-C, something like this: @protocol Handler +(NSString*) getValue; @end

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.