• 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
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

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: 27587
88
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?
 
Where does a nanny get ground to air missles? Protect this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic