zoukankan      html  css  js  c++  java
  • Handler sendMessage 与 obtainMessage (sendToTarget)

    这篇文章讲的很好:

    http://www.cnblogs.com/android007/archive/2012/05/10/2494766.html

    两种用法:

    1、

    private void sendMessage(Handler handler, Bitmap bm) 
        { 
            Message msg = handler.obtainMessage(); 
            msg.obj = bm; 
            handler.sendMessage(msg); 
        }  
    
    private void sendMessage(Handler handler) 
        { 
            Message msg = handler.obtainMessage(); 
            handler.sendMessage(msg); 
        }  
    
    sendMessage(mhandler);
    
    
     

    2、

    Message msg = new Message();
    msg.setTarget(mhandler);
    msg.what = OK;
    msg.sendToTarget();
    

     结论:

    1、obtainMessage 方式性能好;

    Message android.os.Handler.obtainMessage(int what, int arg1, int arg2, Object obj)
    
    public final Message obtainMessage (int what, int arg1, int arg2, Object obj) 
    Since: API Level 1 
    Same as obtainMessage(), except that it also sets the what, obj, arg1,and arg2 values on the returned Message.
    
    Parameters
    what  Value to assign to the returned Message.what field. 
    arg1  Value to assign to the returned Message.arg1 field. 
    arg2  Value to assign to the returned Message.arg2 field. 
    obj  Value to assign to the returned Message.obj field. 
    
    Returns
    A Message from the global message pool.
    
  • 相关阅读:
    php学习推荐
    python 安装numpy报错
    PHP最基础
    php自定义错误函数
    phpMyAdmin安装
    php链接mysql提示:Call to undefined function mysql_connect()
    POJ 1005 解题报告
    亚马逊在线笔试(2014/10/9)
    LeetCode 题目 word break 思路剖析与改进
    Dijkstra单源最短路算法的C++实现
  • 原文地址:https://www.cnblogs.com/sudawei/p/3473605.html
Copyright © 2011-2022 走看看