Waiting for Thread to finish but display Progress Dialog.

Put your problem here if it does not fit any of the other categories.

Waiting for Thread to finish but display Progress Dialog.

Postby Croccy22 » Sun Nov 01, 2009 6:35 pm

Hi,

I'm trying to do something quite simple (I think) but as usual am running into problem.

All I want to do is start a thread which goes off to get some info from the web. Whilst it's doing this I want to display a ProgressDialog. Once it has finished I then want my program to continue.

So far in the onCreate Method I have:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. //Show Progress Dialog
  3.  
  4. pd = ProgressDialog.show(this, "ThreadTest", "Please Wait....",true);
  5.  
  6.  
  7.  
  8. //Start Thread
  9.  
  10. StatusThread thread = new StatusThread();
  11.  
  12. thread.start();
  13.  
  14.  
  15.  
  16. //Wait for Thread to complete
  17.  
  18. //????????
  19.  
  20.  
  21.  
  22. Log.d("ThreadTest","The Thread has completed");
  23.  
  24.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Obviously what happens at the moment is the thread starts and displays the ProgressDialog but the Log.D command is run as soon as the thread starts.

I have tried using thread.jon() which makes it wait but then the ProgressDialog does not get shown?

What is the best way of getting my program to wait until the thread has finished before continuing?

Thanks, Matt.
Croccy22
Developer
Developer
 
Posts: 31
Joined: Wed Dec 03, 2008 3:15 pm

Top

Postby qlimax » Mon Nov 02, 2009 12:12 am

try with this method...
http://www.helloandroid.com/node/243

it's not really the same situation, but i think you can adapt it...

hope it help :?
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby Oleg » Mon Nov 02, 2009 11:01 am

Hi.
There is good solution on HelloAndroid, which is above.
Also you can try a little simple example at
http://thedevelopersinfo.wordpress.com/ ... n-android/
Oleg
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Wed Nov 28, 2007 1:49 pm
Location: Ukraine

Postby padde » Mon Nov 02, 2009 11:12 am

Use AsyncTask.. much more simpler
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 21 guests