I have a counter that counts down, but at the time of leaving the activity it restarts again, I hope this does not happen, I thought that maybe I will have to connect the app with a web page using ViewWeb
, But would it be more tedious, will there be another solution?
I leave you my CountDown
inicar=(Button)findViewById(R.id.iniciar);
inicar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
countDown = new CountDownTimer(9000, 1000) {
public void onTick(long millisUntilFinished) {
contador.setText(""+String.format(FORMAT,
TimeUnit.MILLISECONDS.toHours(millisUntilFinished),
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished) - TimeUnit.HOURS.toMinutes(
TimeUnit.MILLISECONDS.toHours(millisUntilFinished)),
TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) - TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished))));
}
public void onFinish() {
contador.setText("Tiempo terminado!");
}
}.start();
inicar.setEnabled(false);
}
});
pausar=(Button)findViewById(R.id.Reinicar);
pausar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
countDown.cancel();
inicar.setEnabled(true);
contador.setText("Esperando minutos...");
}
});
Thank you!