zoukankan      html  css  js  c++  java
  • Handler机制

        利用Handler来实现UI线程的更新的。

      Handler来根据接收的消息,处理UI更新。Thread线程发出Handler消息,通知更新UI。

    Handler myHandler = new Handler() { 
              public void handleMessage(Message msg) {  
                   switch (msg.what) {  
                        case TestHandler.GUIUPDATEIDENTIFIER:  
                             myBounceView.invalidate();  //更新UI
                             break;  
                   }  
                   super.handleMessage(msg);  
              }  
         }; 

    class myThread implements Runnable {  
              public void run() { 
    while (!Thread.currentThread().isInterrupted()) {   
                          
                        Message message = new Message();  
                        message.what = TestHandler.GUIUPDATEIDENTIFIER;  
                         
                        TestHandler.this.myHandler.sendMessage(message);   //发送消息
                        try {  
                             Thread.sleep(100);   
                        } catch (InterruptedException e) {  
                             Thread.currentThread().interrupt();  
                        }  
                   }  
              }  
         }  

  • 相关阅读:
    Higher-Order Functions and Lambdas
    dispatch_sync:As an optimization, this function invokes the block on the current thread when possible
    为什么使用dispatch_sync
    如何安全使用dispatch_sync
    dispatch_sync
    Dispatch Queues and Thread Safety
    高阶函数-参数与返回值
    In Swift, typedef is called typealias:
    偏函数应用(Partial Application)和函数柯里化(Currying)
    Centos下添加用户到用户组
  • 原文地址:https://www.cnblogs.com/judes/p/5720579.html
Copyright © 2011-2022 走看看