• Post Reply Bookmark Topic Watch Topic
  • New Topic

why it shows Toast message before ends the runnable method

 
sam liya
Ranch Hand
Posts: 1246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is my code.when i click the button it runs the progress dialog,but before end the progress dialog it shows the Toast message.how it happens?


 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a thread and what is its purpose?
 
sam liya
Ranch Hand
Posts: 1246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i need to test progressdialog example.So this is for it.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You misunderstood. new Thread().start() does not do what you seem to think it does. So:
What is a thread and what is its purpose?
 
Joris Bolsens
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does that because you are displaying the toast on a different thread, it displays it as soon as the main thread has finished creating the new thread.
The point of a threads is to be able to do multiple things at once. So even if you tell that thread to wait, the main thread just keeps going.
 
sam liya
Ranch Hand
Posts: 1246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bolsens ,all.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!