android - How to check if a timer is still running or not? -


i try send sms in service.if sms not sent means restart service after time, using timer.if sms sent means want stop timer,for stop timer use timer.cancel(); before i've check timer running or not.how check it?.

             int resultcode = getresultcode();                  switch (resultcode)                   {                 case activity.result_ok:                                               timer.cancel();//here want check timer running or not                  break;                   case smsmanager.result_error_generic_failure:                        timer_run();                  break;                   case smsmanager.result_error_no_service:                           timer_run();                  break;                   case smsmanager.result_error_null_pdu:                               timer_run();                   break;                   case smsmanager.result_error_radio_off:                              timer_run();                   break;                   } 

timer schedule function

    public void timer_run(){              timertask hourlytask = new timertask () {         @override         public void run () {              intent myintent = new intent(myservice.this,myservice.class);               startservice(myintent);           }     };      timer.schedule (hourlytask, 0l, 500*5*5);    }     

there no need check if timer running if want cancel() (this true both timer , timertask).

the documentation states

this method may called repeatedly; second , subsequent calls have no effect.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -