Maybe you should start the timer in the onCreate
method:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(Bundle savedInstanceState);
timer = new Timer();
timer.schedule(new Task(this), 0, 2000);
}
second try with handler:
public class DrawView extends View implements OnTouchListener{
private Timer timer = new Timer();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(Bundle savedInstanceState);
timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
handler.sendEmptyMessage();
}
}, 0, 2000);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
newgame();
}
};
}
I did not compile this but it should work like this.
I noticed another thing: I suppose newgame() should only be called once.
timer.schedule(new Task(this), 0, 2000);does that every 2 secs.
yaourt
2010-08-11 12:03:47