I think what you are trying to accomplish is a callback when the timer expires? If so, you have to think about the timer running by itself and then calling another method when finished. For instance:
public class Main extends Activity
{
private MyCountDownTimer myCountDownTimer;
@Override
public void onCreate(Bundle savedInstanceState){
myCountDownTimer = new MyCountDownTimer(5000, 1000);
myCountDownTimer.start();
}
public void finished(){
Log.e("Testing", "OK na");
}
public class MyCountDownTimer extends CountDownTimer {
public MyCountDownTimer(long startTime, long interval) {
super(startTime, interval);
}
@Override
public void onFinish() {
finished();
}
@Override
public void onTick(long millisUntilFinished) {
Log.e("TESTINg","" + millisUntilFinished/1000);
}
}
}
See this link for more details/example:
https://androidcookbook.com/Recipe.seam;?recipeId=1205
EDIT to make a universal class that can be used in other activities, I would do something like this.
Create a MyCountDownTimer
class that looks like this in its own file:
public class MyCountDownTimer extends CountDownTimer {
private MyCallback myCallback;
public MyCountDownTimer(long startTime, long interval) {
super(startTime, interval);
}
public Interface MyCallBack{
void callback();
}
@Override
public void onFinish() {
myCallback.callback();
}
@Override
public void onTick(long millisUntilFinished) {
Log.e("TESTINg","" + millisUntilFinished/1000);
}
public void setMyCallback(MyCallback myCallback){
this.myCallback = myCallback;
}
}
Then, in each of your activities, you would implement the new interface like so:
public class Main extends Activity implements MyCountDownTimer.MyCallback
{
private MyCountDownTimer myCountDownTimer;
@Override
public void callback(){
Log.e("Testing", "OK na");
}
@Override
public void onCreate(Bundle savedInstanceState){
myCountDownTimer = new MyCountDownTimer(5000, 1000);
myCountDownTimer.setMyCallback(this); //will use the callback method in this class which can be different for each activity
myCountDownTimer.start();
}
}