CountDownTimer.cancel() is working fine for me. I had some issues with it when the screen orientation was changed. Multiple dspCounterObj objects were created when screen orientation changed.
dspCounterObj = new DspCounter(MyApplication.getTimeCount()*1000,1000);
dspCounterObj.start();
I am total Java/Android newbie, i may be wrong, but this is how i solved this.
Every time i create dspCounterObj, i store that in the Application class and
before storing i will get the reference of previously created objects and cancel it.
if(MyApplication.getTimeObjSize()>0){
for(int i=0;i<MyApplication.getTimeObjSize();i++){
tempDSPCounterObj= (DspCounter)MyApplication.getTimeObj(i);
tempDSPCounterObj.cancel();
}
}
dspCounterObj = new DspCounter(MyApplication.getTimeCount()*1000,1000);
MyApplication.setTimeObj(dspCounterObj);
dspCounterObj.start()
public class MyApp extends Application {
..
..
private ArrayList<Object> timeObj;
public int getTimeObjSize(){
return this.timeObj.size();
}
public Object getTimeObj(int i){
return timeObj.get(i);
}
public void setTimeObj(Object timeObj){
this.timeObj.add((Object)timeObj);
}
public void onCreate(){
super.onCreate();
this.timeObj = new ArrayList<Object>(0);
}
}
For some reason I think this is overkill. please don't throw rocks at me.