Restart countodown timer with different timer android -
i making repeating countdown timer app.i require countdown timer restart different time.i using global variable in constructor of countdown timer.but problem restarts starting of first given interval.
public void chance(final int tota, final int cur, final int exercise,int pass,int flag) { log.i("inside value","reached"); = new countdowntimer((tempmilliseconds) * 1000 + 100, 1000) { @override public void ontick(long millisuntilfinished) { tempmilliseconds = (int) millisuntilfinished / 1000; log.i("inside value",integer.tostring(tempmilliseconds)); updatetimer(millisuntilfinished); } @override public void onfinish() { mtext.settext("0:00"); cancel(); final handler handler = new handler(); handler.postdelayed(new runnable() { @override public void run() { currentcompleted++; if (on == 0) { on = 1; int exercis = mainactivity.restmint * 60 + mainactivity.restsec; tempmilliseconds=exercis; chance(tota, curr + 1, exercis, 0, 0); } else { on = 0; int exercis = mainactivity.exermint * 60 + mainactivity.exersec; tempmilliseconds=exercis; chance(tota, curr + 1, exercis, 0, 0); } } }, 1000); } }; a.start(); }
below code resume operations:
public void resume(view view) { button mytext=(button) findviewbyid(r.id.resume); if( mytext.gettext().tostring()=="pause") { mytext.settext("play"); a.cancel(); } else { mytext.settext("pause"); log.i("value of temp",integer.tostring(tempmilliseconds)); a.start(); } }
the timer stopping when started in resume function restarts original time , not specified tempmilliseconds.note tempmilliseconds updated every seconds. help/snippets/suggestions appreciated.thank you!
a countdowntimer
not allow disturbed in case. remember time born till kills it.
if @ documentation you'd see directly inherits object
class , has 4 methods: start()
, cancel()
, onfinish()
(abstract) , ontick()
(abstract). thats pretty it. so, left no choice call cancel()
, re-initialise timer. or, can extend countdowntimer
class , encapsulate under hood.
in either case cost of cancelling ad re-initialising may tedious.
Comments
Post a Comment