Reputation: 173
I am making a quiz app I want to implement the countdown timer of 30 secs
Timer need to be constant on top of page actually. I am calling the same page again and again till the round of 15 Questions is over so in that case I want to main the timer count even after the change of activity
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
// Log.d("Questions", "Moving to next question");
a++;
/**
* validate a Radiobutton has been selected
*/
if (!checkAnswer())
return;
/**
* check if end of game
*/
if (currentGame.isGameOver()) {
db.open();
String total = currentGame.getRight() + "";
db.insertOptions(topic1, total, mon);
db.close();
Intent i = new Intent(this, EndgameActivity.class);
startActivity(i);
a = 0;
finish();
} else {
Intent i = new Intent(this, QuestionActivity.class);
startActivity(i);
finish();
}
At end of timer I want to fire insert query.In above code I am firing the Insert query at end of quiz I am not able to understand how should I implement the timer control.
Upvotes: 1
Views: 1595
Reputation: 3017
Use this function on your onCreate and add stuff to your db on onFinish of countdown
public void startTicking() {
countDownTimer = new CountDownTimer(timerinterval, 1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
db.open();
String total = currentGame.getRight() + "";
db.insertOptions(topic1, total, mon);
db.close();
}
};
}
Upvotes: 1