Before Asking Question let me tell you that this Question has been answered many time but I didn't resolve my problem. I tried this Questions Answer but not really helpful.
So Problem is I am creating a Mastermind Game in android and I want to start the timer from 00:00 when user Enter the first PIN to so on until the user hit the Last PIN or When user Click on New Game Timer will Reset and will not start until User Enter the first PIN again.
So here is my Try
Handler timerHandler = new Handler();
Runnable timerRunnable = new Runnable() {
@Override
public void run() {
long millis = System.currentTimeMillis() - startTime;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
timerTextView.setText(String.format("%d:%02d", minutes, seconds));
timerHandler.postDelayed(this, 500);
}
};
function to start or stop timer
@Override
public void onPause() {
super.onPause();
timerHandler.removeCallbacks(timerRunnable);
timerCheck = true;
}
when user hit the first PIN this code execute
timerCheck = true;
startTimer();
When user hit the Last PIN this Code Execute
timerCheck = false;
startTimer();
Nothing is Working Please Help me To start Timer when First Condition is True and Stop Timer when Last Condition is true, in between if NewGame get Hit Timer will reset and don't start until First Pin got Hit again. Any help will be grateful. Thanks in Advance