Android学习之Activity跳转与传值
2014-05-12 10:23
148 查看
Activity跳转与传值,主要是通过Intent类,Intent的作用是激活组件和附带数据。
一、Activity跳转
方法一
Intent intent = new Intent(A.this, B.class);
startActivity(intent)
方法二
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivity(intent);
实现从A跳转到B(A、B均继承自Activity)
二、传递数据
Activity A 传递数据
方法一
Intent intent = new Intent();
intent.setClass(A.this, B.class);
intent.putExtra("name", "xy");
intent.putExtra("age", 22);
startActivity(intent);
方法二
Intent intent = new Intent(A.this, B.class);
Bundle bundle = new Bundle();
bundle.putString("name", "xy");
bundle.putInt("age", 22);
intent.putExtras(bundle);
startActivity(intent);
Activity B 接收数据
// 获取参数1
Intent intent = this.getIntent();
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 22); // 缺省值为22
// 获取参数2
Bundle bundle = intent.getExtras();
String name2 = bundle.getString("name");
int age2 = bundle.getInt("age", 22);
两种获取参数方式均可,并不是和传参1,2方法一一对应
一、Activity跳转
方法一
Intent intent = new Intent(A.this, B.class);
startActivity(intent)
方法二
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivity(intent);
实现从A跳转到B(A、B均继承自Activity)
二、传递数据
Activity A 传递数据
方法一
Intent intent = new Intent();
intent.setClass(A.this, B.class);
intent.putExtra("name", "xy");
intent.putExtra("age", 22);
startActivity(intent);
方法二
Intent intent = new Intent(A.this, B.class);
Bundle bundle = new Bundle();
bundle.putString("name", "xy");
bundle.putInt("age", 22);
intent.putExtras(bundle);
startActivity(intent);
Activity B 接收数据
// 获取参数1
Intent intent = this.getIntent();
String name = intent.getStringExtra("name");
int age = intent.getIntExtra("age", 22); // 缺省值为22
// 获取参数2
Bundle bundle = intent.getExtras();
String name2 = bundle.getString("name");
int age2 = bundle.getInt("age", 22);
两种获取参数方式均可,并不是和传参1,2方法一一对应
相关文章推荐
- Android学习之Activity跳转与传值
- android activity进行跳转和传值
- Android Activity的跳转:普通跳转(显式跳转,隐式跳转)和传值跳转
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- Android学习之使用startActivityForResult()和onActivityResult()进行跳转并返回数据
- Android学习 (二十) 在fragment里用Intent跳转到其他Activity
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- Android开发 两个Activity之间通过Intent跳转传值
- 【Android基础】页面跳转与传值(Activity跳转与传值) .
- [Android新手学习笔记05]-如何进行活动Activity之间的跳转以及数据传递
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- android学习--activity跳转报错--以及怎么确定哪一个activity开始
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- Android实现两个Activity界面的跳转并传值
- Android基础】页面跳转与传值(Activity跳转与传值)
- 【Android基础】页面跳转与传值(Activity跳转与传值)
- 学习(三)页面跳转与传值(Activity跳转与传值)
- Android学习 - 小知识(读取一个已经安装的包的权限与两个Activity跳转的时,如何自定义翻页效果)
- Android Activity之间跳转与传值
- 【Android基础】页面跳转与传值(Activity跳转与传值)