• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why postdelayed is not working here?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does the timer stop working when i put the postDelayed(this,1000);  inside the if statement,just under seconds++;?
Like this....
If(running){
seconds++;
postDelayed(this,1000);
}
Screenshot_2017-11-21-18-03-42.png
[Thumbnail for Screenshot_2017-11-21-18-03-42.png]
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because postDelayed() is what causes the next cycle of the timer to happen. In your case it schedules the timer to go off 1000 milliseconds in the future. So if you only do that when running is true, then as soon as you set running to false, you no longer tell the timer to keep going.
 
Yl Ong
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So postdelayed() method causes the timer to keep looping?when i read about postdelayed method online.it only says that it will cause the delay of execution...how about post() method?

So you mean that in default running is false,so postdelayed wont execute.thus the loop stops.am i right?
 
Yl Ong
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i need 2 post() method...1 inside of the other so it will keep looping right?
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic