android中handler和bundle有什么区别和联系 都是用来传递消息吗都是信息的载体吗

如题所述

1、handler是消息处理者,通常重写Handler的handleMessage()方法,在方法中处理接收到的不同消息,例如:

Handler mHandler=new Handler(){
     
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 110:
progressValue += msg.arg1;
pb_horizontal.setProgress(progressValue);
Log.d("progressValue-------------->", progressValue+"");
break;

}
}
}

2、Bundle是一个载体,可以存放基本数据类型、对象等内容,好比是一辆货车,可以装各种东西,然后运到需要的地方,例如:

Bundle mBundle=new Bundle();
mBundle.putString("name","zhaolinit");
mBundle.putInt("number",123456);
mBundle.putBoolean("flag",false);
//然后,放到Intent对象中
Intent mIntent=new Intent();
mIntent.putExtras(mBundle);

3、关于Handler和Bundle的更多介绍,可以百度:TeachCourse空间,希望可以帮助到你!!!

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网