Because my countdowntimer treats the received time according to the mobile

Asked

Viewed 20 times

0

I have a countdowntimer that gets a long value of 86400000 ( 24 hours ) on my emulator android 5.1 it recognizes 24 hours and starts counting since then, but on other emulators and on my physical phone it does not start in 24 hours, it starts in 20, 18 hours, varies the device time. I don’t understand.

Code of my countdowntimer

private void contagemregressiva(final long temporestante) {
        Log.d(TAG,"tempo restante recebido na contagem: " + temporestante);
        new CountDownTimer(temporestante, 1000) {

            public void onTick(long millisUntilFinished) {
                SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
                Date date = new Date(millisUntilFinished);

                txv_temporestante.setText(dateFormat.format(date));
                temporestanteaa = millisUntilFinished;
            }
            public void onFinish() {
                dados.setDia(dados.getDia()+1);
                dados.setContagemVirou(true);
                atualizarUI();
            }
        }.start();
    }

1 answer

0

Solved, it was problems with locality, not to suffer from this problem, format the time so:

public void onTick(long millisUntilFinished) {

                long second = (millisUntilFinished / 1000) % 60;
                long minute = (millisUntilFinished / (1000 * 60)) % 60;
                long hour = (millisUntilFinished / (1000 * 60 * 60)) % 24;

                String time = String.format("%02d:%02d:%02d", hour, minute, second);
                txv_temporestante.setText(time);
                temporestanteaa = millisUntilFinished;
            }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.