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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:48:38+00:00 2026-06-01T14:48:38+00:00

I updated my code like Andro wrote about to me: public class ZiiziiActivity extends

  • 0

I updated my code like Andro wrote about to me:

public class ZiiziiActivity extends Activity {
    ProgressDialog pd;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        pd = new ProgressDialog(ZiiziiActivity.this);
        final Handler handler = new Handler()
        {
            public void handleMessage(Message msg)
            {
                if(msg.what==0)
                {
                    pd.dismiss();
                }
            }
        };

        Button end = (Button) findViewById(R.id.button2);
        end.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                pd.setMessage("Working...");
                pd.setIndeterminate(true);
                pd.setCancelable(false);
                pd.show();
                Thread t = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i=0;i<1000000;i++)
                        {
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } //To denote a delay in background processing
                        }
                        handler.sendEmptyMessage(0);
                    }
                }); t.start();
            }
        });
    }
}

But when the progress start, it never ends.

What can be wrong?

  • 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-01T14:48:40+00:00Added an answer on June 1, 2026 at 2:48 pm

    This is so simple. The basic fact behind this is as follows.

    Your progress dialog runs in the main UI. Your for loop here gets executed so soon and takes more priority and hence you are not able to see your progress dialog but the fact is, your code works fine and progress dialog does show up for fraction of seconds which the human eye can’t catch.

    Usually people use a progress dialog when they do something in the background thread and not the main thread. So you will have to change a little bit of your code. They are,

    1) Surround your for loop with a thread like this,

        Button end = (Button) findViewById(R.id.button2);
        end.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                ProgressDialog pd = new ProgressDialog(ZiiziiActivity.this);
                pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                pd.setMessage("Working...");
                pd.setIndeterminate(true);
                pd.setCancelable(false);
                pd.show();
                Thread t = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        for (int i=0;i<1000000;i++)
                        {
                            Thread.sleep(100); //To denote a delay in background processing
                        }
                        handler.sendEmptyMessage(0);
                    }
                });
                t.start();
            }
        });
    

    2) Now add a handler to your onCreate() like this:

        handler = new Handler()
        {
            public void handleMessage(Message msg)
            {
                if (msg.what == 0)
                {
                    pd.dismiss();
                }
            };
    

    Note that you can’t update your UI from a background thread. So in order to update the UI from some other worker thread you go for handlers. So once your for loop gets completed, a call will be made to handlers which updates the UI. (In this case it cancels the progress dialog).

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

Sidebar

Related Questions

I have a JavaFX app with a some code like this... public class MainListener
I have an camera Activity like this: public void startCamera() { Log.d(ANDRO_CAMERA, Starting camera
I have updated my code to look like this. When I run it though
Say, the code class Derived: public Base {....} Base* b_ptr = new( malloc(sizeof(Derived)) )
* *Updated code as of 3-28 Index.php <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
Hello I'm having a problem here. The code looks like this. private void Form3_Load(object
I have some code to update a database table that looks like try {
I am trying to update values in a column like the following code block
I have updated code for ActiveX functionality which already installed on client(in their Windows
I updated my code with string dates created with new Date and added back

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.