android - problems with CountDownTimerWithPause -


i'm trying use timer, on question suggested:

https://stackoverflow.com/questions/13806545/how-to-extend-countdown-timer-with-pause,

but doesn't work expected. pause/resume works fine, if cancel , recreate timer, counting starts last paused time. need start initial value. eg counter's intial value 3 minutes. if paused @ 2 minutes, when i'm trying create again starts 2 minutes. help?

    public class mainactivity extends buttonmethods implements onclicklistener {        private countdowntimerwithpause timerpausable = null;     int milis = 180000;  @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);  timerpausable = new countdowntimerwithpause(milis, 1000, true) {              @override             public void ontick(long millisuntilfinished)             {                 timer.settext("" + millisuntilfinished / 1000);             }              @override             public void onfinish()             {                 timer.settext("180");                 disablerandombuttons(); @override     public void onclick(view v) {          switch (v.getid()) {         case r.id.bnewword:                  if(clicked == false){                     clicked = true;                     timerpausable.create();                              }                 else{                     clicked = false;                     timerpausable.cancel();                     timerpausable=null;                     milis=180000;                     timerpausable.create();             }              break;              case r.id.imageview2:         tapsound.start();         if(isclicked == false){             isclicked = true;             timerpausable.pause();                    }         else{             isclicked = false;         timerpausable.resume();             }             break; 

its hard exact problem without seeing code did call cancel() on timer make equal null reset it. mine little different , handle in onbackpressed()

@override public void onbackpressed() {     super.onbackpressed();     timer.cancel();          // timer reference inner countdowntimer class     timer = null;     secs = 10; } 

i think looking for. works me.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -