您的位置:首页 > 移动开发 > Android开发

Android 两个activity传递数据方法

2017-06-17 09:58 323 查看
方法一:直接利用Intent

传递代码示例:

Intent intent = new Intent();

intent.putExtra("name", "张三");  

intent.putExtra("age", 25); 

接收代码:

String name = intent.getStringExtra("name");  

int age = intent.getIntExtra("age", 0); 

方法二:利用Intent和Bundle

传递代码示例:

Intent intent = new Intent();

Bundle bundle = new Bundle();  

bundle.putString("name", "张三");  

bundle.putInt("age", 25);  

intent.putExtras(bundle);  

接收代码:

Intent intent = getIntent();

Bundle bundle = intent.getExtras();  

String name = bundle.getString("name");  

int age = bundle.getInt("age", 0); 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: