timeLeft fonctionne pour la lecture de fichiers musicaux, mais comment travailler avec onResume? Je peux donc mettre l'activité en pause, puis reprendre avec la minuterie de gauche.Comment utiliser timeLeft pour reprendre countdowntimer sur Android?
Voici mon code:
public void countdownTimer() {
final TextView mTextField = (TextView)findViewById(R.id.timer);
Count = new CountDownTimer(TIMER, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("" +(millisUntilFinished/60000));
long timeLeft = millisUntilFinished/1000;
if(timeLeft <= 4 && timeLeft >=2 && tgbutton.isChecked())
{
mSoundPool.play(sixthMusicFile, 1f, 1f, 1, 0, 1f);
}
if(timeLeft <= 1 && tgbutton.isChecked())
{
mSoundPool.play(seventhMusicFile, 1f, 1f, 1, 0, 1f);
vibrate();
}
}
public void onFinish() {
Count.setText("done!");
}
}.start();
}
ÉDITÉ: Enfin, je me suis une réponse. Code de travail ici: Android CountDown Timer with Pause, Resume and Cancel button. Un grand merci à tous ceux qui m'aident avant.
Qu'est-ce que vous avez besoin est ici: http://stackoverflow.com/a/10055480/5552022 –
Merci pour la réponse @ omar-Aflak. Mais très confus moi. – Bonnie7
Fondamentalement ce dont vous avez besoin est un CountDownTimer que vous pouvez mettre en pause/reprendre quand vous voulez, n'est-ce pas? –