Skip to content Skip to sidebar Skip to footer

Passing Countdown Timer Beetwen Activities In Android

I'm trying to pass the a CountDownTimer value from Activity 1(PrimerNivel) to Activity 2(SegundoNivel)and start the CountDownTimer in Activity 2 from the value that got from the Ac

Solution 1:

You are creating the CountDownTimer before getting the value. Simply move the code that creates the timer to below where you get the value.

publicvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.juego);
    cuentaRegresiva=(TextView)findViewById(R.id.cuentaRegresiva);

    bundle = getIntent().getExtras();
    startTime= bundle.getLong("regresivaAnterior")/1000;

    // move it here after you've gotten the value
    countDownTimer = newMyCountDownTimer(startTime, interval);
    cuentaRegresiva.setText(""+startTime);
    countDownTimer.start(); 

You may need to cancel your first timer to get the correct value at the correct time. Try calling

countDownTimer.cancel();
countDownTimer = null;

before creating the Intent. Also, you are dividing the startTime by 1000 after you get the value from the Intent. I'm not sure you want to be doing that.

Post a Comment for "Passing Countdown Timer Beetwen Activities In Android"