Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynch thread stopping main UI thread

Can anyone tell me why the following dialog box does not show until the asynchronous thread has finished. I cannot figure this one out. This is running in the main UI thread. Not sure why a new thread would affect the flow of the main UI thread

                dialog = new ProgressDialog(this);

                dialog.show();

                new Thread(new Runnable() {
                     public void run() {
                         while(imageLoader.isProcessing()) {}
                         doSomething();   
                     }
                 }).run();
like image 856
akupun Avatar asked Apr 09 '26 18:04

akupun


1 Answers

You need to call the start() method of the anonymous Thread, not the run() method.

From the docs:

public void start(): Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.

like image 192
titaniumdecoy Avatar answered Apr 11 '26 06:04

titaniumdecoy