javascript - How do i cancel a timeout if a button is pressed? -


i have layout buttons, , want after 1 of them pushed cancel timeout, code have press 1 of buttons , redirects me activity timer dons't stop , after 3 seconds redirects me again, how cancel timer if 1 of buttons pressed? timer:

int timeout = 3000;  seconds    timer timer = new timer();  timer.schedule(new timertask() {        @override      public void run() {          finish();          intent homepage = new intent(act1.this, act2.class);          startactivity(homepage);      }  }, timeout);

check documentation , find timer.cancel(). keep reference timer , call whenever want make stop.

void cancel()

terminates timer, discarding scheduled tasks.

example:

mbutton.setonclicklistener(new view.onclicklistener() {     @override     public void onclick(view v) {         mtimer.cancel();     } }); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -