Emrah Şentürk
Emrah Şentürk

Reputation: 107

How to kill CountDownTimer When I start an activity?

I have two activities. ActivityA has a countdowntimer. When I start ActivityB from ActivityA , timer doesn't stop. How can I do it ?

myTimer = new CountDownTimer(20000, 1000) { 
    @Override public void onFinish()

     Intent mainIntent = new Intent(QRcode.this,ActivityC.class); 
     QRcode.this.startActivity(mainIntent);

}; 
myTimer.start();
Intent mainIntent = new Intent(QRcode.this,ActivityB.class); 

QRcode.this.startActivity(mainIntent);

Upvotes: 2

Views: 3190

Answers (1)

codeMagic
codeMagic

Reputation: 44571

In ActivityA run this code before you start ActivityB

    myTimer.cancel();
    myTimer = null;

and reset your start time 20000. Now when this Activity is created again it should reset your CountDownTimer object.

Upvotes: 4

Related Questions