handler刷新主界面

发布时间:2016-12-9 0:28:52 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"handler刷新主界面",主要涉及到handler刷新主界面方面的内容,对于handler刷新主界面感兴趣的同学可以参考一下。

Android中主线程的职责是创建、显示和更新UI控件、处理UI事件、启动子线程、停止子线程。 子线程的职责是处理后台逻辑,向主线程发送UI更新。 实例化一个Handler对象,并重写handleMessage方法调用invalidate()实现界面刷新;而在线程中通过sendMessage发送界面更新消息。          // 在onCreate()中开启线程        new Thread(new GameThread()).start();、          // 实例化一个handler        Handler myHandler   = new Handler()        {               //接收到消息后处理               public void handleMessage(Message msg)               {                      switch (msg.what)                      {                      case Activity01.REFRESH:                             mGameView.invalidate();        //刷新界面                             break;                      }                      super.handleMessage(msg);               }                          };          class GameThread implements Runnable        {               public void run()               {                      while (!Thread.currentThread().isInterrupted())                      {                             Message message = new Message();                             message.what = Activity01.REFRESH;                             //发送消息                             Activity01.this.myHandler.sendMessage(message);                             try                             {                                    Thread.sleep(100);                             }                             catch (InterruptedException e)                             {                                    Thread.currentThread().interrupt();                             }                      }               }        }

上一篇:SIP代理服务器(2)
下一篇:spring和CXF集成来实现webservices

相关文章

相关评论