安卓定时有两个,一个是AlartManager,一个是TimerTask,你这种情况推荐使用TimerTask,如果没有用过可以百度搜索一下android timertask 有很多结果,并且使用起来非常简单。
timer = new Timer();
timer.schedule(new TimerTask(){
public void run(){
System.out.println("Time's up!");
timer.cancel();
}
}, sec*1000);
不应该是 mainhandler.removeCallbacks(runnable); 吗
你加这一句是想干什么:mainhandler.removeCallbacks(this);