private void StartVideoTimer(int countdownPeriod){ Log.d(LOG_TAG, "[startVideoTimer] - Starting timer for video (in calibration), countdown period = " + countdownPeriod); /**tried to cancel here*/ // if (inCalibrationVideoTimer != null) { // inCalibrationVideoTimer.cancel(); // inCalibrationVideoTimer = null; // } streamIsRunning = true; inCalibrationVideoTimer = new CountDownTimer(countdownPeriod, VIDEO_TIMER_INTERVAL) { @Override public void onTick(long millisUntilFinished) { final int secondsLeft = (int) millisUntilFinished / 1000; Log.d(LOG_TAG, "[onTick] - Seconds left = " + secondsLeft); SharedPreferences.Editor editor = getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE).edit(); editor.putInt("inCalibrationvideoTimerCountdown", secondsLeft); editor.apply(); try { if (streamIsRunning) { runOnUiThread(new Runnable() { @Override public void run() { videoTimeTextView.setText(String.format(getString(R.string.common_timer_format), secondsLeft)); } }); } } catch (IllegalStateException e) { e.printStackTrace(); } } @Override public void onFinish() { try { if (streamIsRunning) { runOnUiThread(new Runnable() { @Override public void run() { videoTimeTextView.setText(String.format(getString(R.string.common_timer_format), 20)); } }); } } catch (IllegalStateException e) { e.printStackTrace(); } } }.start(); /**tried to cancel here but not working*/ }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)