Because my countdowntimer treats the time received according to the cell phone

0

I have a countdowntimer that gets a long value of 86400000 (24 hours) in my android 5.1 emulator it recognizes 24 hours and starts counting since then but in other emulators and in my physical phone it does not start in 24 hours, it starts at 20, 18 hours, varies device time. I do not 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();
    }
    
asked by anonymous 26.08.2017 / 19:14

1 answer

0

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

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;
            }
    
26.08.2017 / 21:38