惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - M'

AndroidStudio修改项目名称 cocos2dx2.x&3.x部分函数对照表 Ubuntu 安装mono 关于BigDecimal.ROUND_HALF_UP与ROUND_HALF_DOWN android 常用框架 理解assign,copy,retain变strong SQLSERVER2008R2正确使用索引 除非 Windows Activation Service (WAS)和万维网发布服务(W3SVC)均处于运行状态,否则无法启动网站。目前,这两项服务均处于停止状态。 Android资源命名规范 eclipse导入Android项目后,项目的名称变为了主Activity的名称 C语言位运算详解[转] Android---组件篇---Handler的使用(1)[转] 自定义登录后台(authentication backend)[转] Nginx配置文件详细说明[转] python 进制转换[转] MySQL一些优化[转] C# Stream 和 byte[] 之间的转换[转] DotLucene(Lucene.Net)研究[转] MySQL 去除重复的方法
Android Message里传送的数据[转]
M' · 2013-07-12 · via 博客园 - M'
package org.hualang.handlertest;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

public class HandlerTest4 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Log.d("System.out","Activity所在线程的id:"+Thread.currentThread().getId());
        /**
         * 生成一个HandlerThread对象,实现了使用Looper来处理消息队列的功能
         * 这个类由Android应用程序框架提供
         */
        HandlerThread handlerThread = new HandlerThread("handlerThread");
        /**
         * 使用HandlerThread的getLooper()方法之前,必须先调用该类的start()方法,否则是个null,会报错
         */
        handlerThread.start();
        MyHandler handler = new MyHandler(handlerThread.getLooper());
        Message msg = handler.obtainMessage();
        /**
         * 将Message对象发送到目标对象
         * 所谓的目标对象,就是生成该msg对象的handler对象
         */
        //msg.obj = "Hello world";
        Bundle b = new Bundle();
        b.putInt("age", 22);
        b.putString("name", "loulijun");
        msg.setData(b);
        msg.sendToTarget();
    }
    class MyHandler extends Handler
    {
    public MyHandler()
    {
    }
    public MyHandler(Looper looper)
    {
    super(looper);
    }
    public void handleMessage(Message msg)
    {
    //String str = (String)msg.obj
    Bundle b = msg.getData();
    int age = b.getInt("age");
    String name = b.getString("name");
    Toast toast = Toast.makeText(getApplicationContext(), "age="+age+"name="+name, Toast.LENGTH_LONG);
    toast.show();
    Log.d("System.out", "handler所在线程的id:"+Thread.currentThread().getId());
    }
    }
}

如果是msg.obj,那么可以这样用

msg.obj = "Welcome to china";

然后在handleMessage()方法中用

String str = (String)msg.obj;来获得传递的值

如果使用getData()方法的话,需要用到Bundle对象来传递

来自:http://www.iteye.com/topic/1063216