Intent 传递数据

使用INtent 在页面之间跳转,数据传递是必须的,我们可以直接在intent 对象上放置基本数据类型的数据,也可以放置字符串和其他数据类型数据。对于其他数据类型,实现了Parcelable 或Serializable 接口就可以。

Intent intent = new Intent();

intent.setClass( this,MenuActivity.class);
//数据传递 方式一:
/* intent.putExtra("name", "张三");
intent.putExtra("age",  12 );
startActivity(intent); */
 

//数据传递 方式2:

用Bundle来实现数据的传递:

//创建 Bundle对象
Bundle bundle = new Bundle();
bundle.putString("name", "张三");
bundle.putInt("age", 22);
intent.putExtras(bundle); 
startActivity(intent);  
//--end
posted @ 2013-07-02 10:47  一个学渣  阅读(329)  评论(0编辑  收藏  举报

 

CSDNGitHub 联系邮箱:aikongmeng@gmail.com


Copyright 2008-2019 Government All Rights Reserved