博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
timer
阅读量:4222 次
发布时间:2019-05-26

本文共 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/

你可能感兴趣的文章
Ubuntu终端多窗口分屏Terminator
查看>>
linux下的find文件查找命令与grep文件内容查找命令
查看>>
linux中快速清空文件内容的几种方法
查看>>
MySQL数据库改名的三种方法
查看>>
printf()详解之终极无惑
查看>>
logrotate 配置文件强制为 0644 属性
查看>>
使用 logrotate对centos中各服务程序的日志文件进行转储
查看>>
Qt程序打包发布方法(使用官方提供的windeployqt工具)
查看>>
Select中DISTINCT关键字的用法?
查看>>
一次segfault错误的排查过程
查看>>
利用dmesg和addr2line来重现bug
查看>>
addr2line命令使用
查看>>
用gdb 查看,执行汇编代码
查看>>
一步一步学调试——gdb命令小结
查看>>
linux程序莫名异常怎么查
查看>>
Linux进程退出详解(do_exit)--Linux进程的管理与调度(十四))
查看>>
python ctypes 探究 ---- python 与 c 的交互
查看>>
Python如何运行程序
查看>>
Qt容器遍历
查看>>
使用 ctypes 进行 Python 和 C 的混合编程
查看>>