0

I want to put a ProgressDialog on my program while calculating something.I tried many things but any of them helps me.Here is my code ;

                dialog=ProgressDialog.show(this, "calculating", "Please wait while the calculation is getting done.",true);

                this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub

                changeHelp = 0;

                if(screenNumber == 1){
                    compareImages(3.3, 0.12);
                }

                else if(screenNumber==2 || screenNumber == 4){
                    compareImages(1.4, 0.1);
                }
                else if ( screenNumber == 3)
                    compareImages(0.41, 0.1);
                else
                    compareImages(3.3, 0.0676);

                dialog.dismiss();

                screenNumber++; }
        });

There are a lot of question in there about this problem.Although ı tried many of them,ı couldn't deal with the problem.I don't want to use asynctask.Pls help me .

----EDİT----

I have added thread.sleep(2000) in try but it is still not working.I think that ı am doing something wrong in while putting dialog.dismiss but ı couldn't find where the problem is?

begin_EN
  • 149
  • 1
  • 2
  • 11

1 Answers1

0

I think that your ProgressDialog was shown but for a very little time because you are not doing task that lasts at least second but much more shortly.

If you want to achieve your goal better approach is to use AsyncTask, yes you don't want to use it but for your goal AsyncTask is i think the best approach you can use.

But as workaround solution there is method Thread.sleep() for simulating some task that "will last" longer. But you need to call in from backround Thread (to avoid UI freezing). Advance of dialogs is that can be dismissed from any kind of Thread.

Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106