本文共 527 字,大约阅读时间需要 1 分钟。
1, 启动定时器
Timer timer;
//timer = new Timer(true); //timer.schedule(task,15000, 1000);
2,指定定时器的任务
TimerTask task = new TimerTask(){ public void run() { Message message = new Message(); message.what = 1; mainHandler.sendMessage(message); } };
3,定义handler, 只有在UI线程中才能对view操作
mainHandler = new MainHandler(getMainLooper());
class MainHandler extends Handler{ public MainHandler(Looper looper) { super(looper); } public void handleMessage(Message msg) { Log.d("mainthread", "i get message \n"); //mAdsView.hide(); timer.cancel(); } }
转载地址:http://noomi.baihongyu.com/