I need to send a SMS in a future time, i.e. in 5 minutes, and to show in the UI the remaining time in the format 00:00.
My first choice was using android-alarm, but I dont know how to show in the layout the countdown.
Next, I tried to use a chronometer, and use the view of the object, but the time is always up, so i'd need to make a lot of math operations to refresh the view.
Finally I've used a CountDownTimer, and i show in a TextView the elapsed time.
That is the best choice?
Here is a short of code:
public void startCountDown(View v) {
if (!activedCountDown) {
activedCountDown = true;
final TextView mTextField = (TextView) findViewById(R.id.mTextField);
EditText text = (EditText) findViewById(R.id.etMinutos);
String mins = text.getEditableText().toString();
futureTime = Integer.parseInt(mins) * 60000;
isTheFinalCountDown = new CountDownTimer(futureTime, interval) {
@Override
public void onTick(long millisUntilFinished) {
if (millisUntilFinished < 60000) {
mTextField.setText("00:" + millisUntilFinished / 1000);
} else {
//TODO parse the textfield to show minutes and seconds
}
}
@Override
public void onFinish() {
//TODO: launch SMS
mTextField.setText("Send SMS now");
activedCountDown = false;
}
}.start();
}
}