• AndroidのHandler与Message


    1.HandlerThread+Handler+Message

    package com.bvin.study.message;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Handler.Callback;
    import android.os.HandlerThread;
    import android.os.Message;
    
    public class MainActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            HandlerThread ht = new HandlerThread("HandlerThread");
            ht.start();
            
            Handler handler = new Handler(ht.getLooper(),new Callback(){
    
                @Override
                public boolean handleMessage(Message msg) {
                    // TODO Auto-generated method stub
                    setTitle((String)msg.obj);
                    return true;
                }
                
            });
            
            Message msg = handler.obtainMessage();
            msg.obj = "就是我";
            msg.sendToTarget();//发送至生成嘴个消息的Handler
        }
    }
  • 相关阅读:
    Spring----MyBatis整合
    VueRouter案列
    Vue-Router
    axios用法
    Fetch的使用
    Promise用法
    组件之间传值
    局部组件注册方式
    学习组件与模板
    如何实现new,call,apply,bind的底层原理。
  • 原文地址:https://www.cnblogs.com/bvin/p/2665772.html
Copyright © 2020-2023  润新知