android - How can I tell MyCountDownTimer to quit whenever a certain activity isn't opened? -


the project i'm working on quiz timer on each question. 30 seconds. noticed if finish test before timer runs out, timer doesn't stop running. if head on test, notification haven't finished test popup , overide current activity.

here mycountdowntimer class

public mycountdowntimer(textview textcounter, long millisinfuture, long countdowninterval) {             super(millisinfuture, countdowninterval);             this.textcounter = textcounter;         }      @override     public void ontick(long millisuntilfinished) {         textcounter.settext(string.valueof(millisuntilfinished / 1000));      }      @override     public void onfinish() {           intent retryintent = new intent(textcounter.getcontext(), retry.class);             if (textcounter.getcontext() instanceof test1){                whichtest = 1;                retryintent.putextra("whichtest",whichtest);            }         if (textcounter.getcontext() instanceof test2){             whichtest = 2;             retryintent.putextra("whichtest",whichtest);         }          if (textcounter.getcontext() instanceof test3){             whichtest = 3;             retryintent.putextra("whichtest",whichtest);         }         if (textcounter.getcontext() instanceof test4){             whichtest = 4;             retryintent.putextra("whichtest",whichtest);         }          if (textcounter.getcontext() instanceof test5){             whichtest = 5;             retryintent.putextra("whichtest",whichtest);         }         if (textcounter.getcontext() instanceof test6){             whichtest = 6;             retryintent.putextra("whichtest",whichtest);         }         if (textcounter.getcontext() instanceof test7){             whichtest = 7;             retryintent.putextra("whichtest",whichtest);         }          textcounter.getcontext().startactivity(retryintent);    } 

edit: additional code if (textcounter==null){

                mycountdowntimer.onfinish();              }           } else  {              // string score7s = integer.tostring(score7);             mycountdowntimer.cancel();             intent intent7 = new intent(test7.this, usersanswers7.class);             intent7.putextra("usersanswers7", usersanswers7);             intent7.putextra("isatof7", isatof7);             intent7.putextra("score7", score7);             startactivity(intent7);         } 

countdowntimer has cancel() method.

http://developer.android.com/reference/android/os/countdowntimer.html#cancel()

call whenever user "finishes test" in time , onfinish() won't called.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -