package com.proper;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;

public class HandlerThreadActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
System.out.println("线程Id"+Thread.currentThread().getId());
HandlerThread handlerThread=new HandlerThread("handlerThread");
handlerThread.start();
MyHandler myHandler=new MyHandler(handlerThread.getLooper());
Message msg=myHandler.obtainMessage();
Bundle bundle=new Bundle();
bundle.putInt("age", 24);
bundle.putString("name", "Robin");
msg.setData(bundle);
msg.sendToTarget();
}
class MyHandler extends Handler{

public MyHandler(){}
public MyHandler(Looper looper ){
super(looper);
}
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
Bundle bundle=msg.getData();
int age=bundle.getInt("age");
String name=bundle.getString("name");
System.out.println("线程Id"+Thread.currentThread().getId());
System.out.println("名字"+name+"-------"+"年龄"+age);

}

}
}

更多相关文章

  1. SpringBoot 2.0 中 HikariCP 数据库连接池原理解析
  2. 定制apk名字
  3. android 消费者和生产者的队列处理模型
  4. Android如何调用webservice 以及错误解决汇总
  5. Android与Javascript交互示例(三)
  6. Android手机监控应用(二)
  7. Application 判断 是否在主进程、主线程
  8. Android在SurfaceView做动画一般方法
  9. Android(安卓)Service学习之IntentService 深入分析

随机推荐

  1. Android 代码设置Color的几种方式
  2. 开始学习、翻译android文档
  3. android studio在编辑时出现如Failed to
  4. Cocos2d-x12和NDK-r8编译android
  5. 弹出sub View在当前窗口
  6. A simple guide to 9-patch for Android
  7. Android电池信息(Battery information)
  8. 【Android】两步搞定AndroidSDKManager在
  9. libGDX引擎在android APP开发中应用系列-
  10. anr日志