I am writing a Cowndown timer, and I have a countdowntimerController that implements the Observer interface. It has an inner class called a countdown, which extends the Observable class and implements the Runnable interface. However, my controller does not receive notifications when runnable ends. Below are my codes, please tell me where I was wrong. Postscript since Observer is inside Observable, I used countdown.addObserver (this), is this a problem?
public class CountdownTimerController extends ActivityController implements Observer {
private Handler handler = new Handler();
private void startTimer(int posi) {
Countdown countdown = new Countdown();
countdown.addObserver(this);
handler.post(countdown);
}
public void update(Observable arg0, Object arg1) {
Log.d("countdownController", "update");
}
private class Countdown extends Observable implements Runnable {
public void run() {
long millis = countdownTime - (System.currentTimeMillis() - startTime) + pausedTime;
if(millis <=0) {
onFinish();
return;
}
handler.postDelayed(this, 100);
}
public void onFinish(){
notifyObservers();
handler.removeCallbacks(this);
}
};
}
source
share