The project I am working on is a quiz with a timer on every question. For 30 seconds I saw that if you finish the test before the end of the timer, the timer does not stop running. So if you go ahead in any other examination, the notification that you have not finished the exam, the current activity is popup And will override. I tried to use the cancellation method, but I'm sure I'm doing it wrong.
Here is a snippet of MyCountDownTimer class
public MyCountDownTimer (TextView textCounter, long millise infusion, long calculation down interval) {super (millise infue, countdown interpreter); This.textCounter = textCounter; } @ Override Public Recording ontic (long milliseconds available) {textCounter.setText (String.valueOf (Million Utility / 1000)); } @ Override public empty on finish () {Intent retrieval = new intent (textquarter .Get Context (), retrieval class); If (textCounter.getContext () example test1) {thatTest = 1; RetryIntent.putExtra ("whichTest", whichTest); } TextCounter.getContext (). StartActivity (try again); }
This is a snippet of activity that implements the method
@override Create a secure over zero (bundle savedinstenstate) {super. OnCreate (savedInstanceState); SetContentView (R.layout.test_page); TextCounter = ((TextView) findViewById (R.id.textCounter)); MyCountDownTimer = New MyCountDownTimer (TextCountor, 29000, 1000); MyCountDownTimer.start (); TextCounter.setText (""); MyCountDownTimer.onTick (29000); } @ Override Public Zero (see V) {if (questionindex == questions7.length) {myCountDownTimer.cancel (); Intent intent1 = new intent (test 1. this, User Answers1.class); Intent1.putExtra ("usersAnswers1", usersAnswers1); Intent1.putExtra ("isATOF1", isATOF1); Intent1.putExtra ("Score 1S", Score 1S); StartActivity (intent1); }}
Override the top method of your activity and use the code like < / P>
@ override protected ontop () {myCountDownTimer.cancel (); Super.onStop (); }
So whenever your activity goes in the background, it will cancel any timers associated with the current activity.
No comments:
Post a Comment