Intent的两种跳转方式
来源:互联网 发布:毕业论文里的数据作假 编辑:程序博客网 时间:2024/06/03 17:54
Intent的两种跳转方式
无返回值的跳转
以点击按钮跳转到下一个页面,在Button的监听事件中写
Intent intent =new Intent([ActivityName].this,[TagActivity].class);startActivity(intent);
然后在manifest.xml中声明一个那个Activity就好了。
这样就可以实现跳转了,当点击按钮时可以跳转到对应的页面
有返回值的跳转
在activity1中先同样用按钮启动为例,需要使用startActivityForResult(Activity activity, Intent intent, int requestCode, Bundle options)
(注,有的可能没有第一个(activity)参数,无碍)方法:
startActivityForResult(intent,requestCode);
重写onActivityResult方法
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { //取得从Result返回值 super.onActivityResult(requestCode,resultCode,data); //对requestCode和ResultCode进行判断,执行相应的动作 ........ }
在目标Activity中,新建一个按钮并注册监听事件,要将数据返回可用一下方法public final void setResult (int resultCode, Intent data)
。
具体实现代码: Intent intent=new Intent();
intent.putExtra("msg",data);
setResult(2,intent);
finish();
之所以同时有请求吗和结果码,是当有多个页面都要返回数值时,只有这样才能确定唯一的一个信息:请求码为requestCode,结果码为IntentCode码的一条数据.
Tips:请求回传的数据不是主动回传的,而是自己被动返回的。
1 0
- Intent的两种跳转方式
- android:Intent的两种跳转
- Intent的跳转方式
- Activity生命周期以及Intent两种画面跳转方式
- Intent跳转的2种方式
- Intent跳转页面的几种方式
- 两种Intent的实现方式
- Intent传递对象的两种方式
- intent传递对象的两种方式
- Intent 启动 Activity的两种方式
- 显、隐式Intent的两种方式
- android自学 intent 页面跳转的两种方法
- jsp的两种跳转方式
- jsp的两种跳转方式
- 两种跳转方式的区别
- response的两种跳转方式
- ios的两种界面跳转方式
- Apache 301 跳转的两种方式
- 面试笔试杂项积累-leetcode 116-120
- Android 获取各种时间组合
- cf#AIM Tech Round -C. Graph and String-贪心/ 二分图染色
- JavaScript菜鸟教程Object2
- java中递归方法的应用--计算n的阶乘
- Intent的两种跳转方式
- 数据结构基础之串
- cf#AIM Tech Round -B. Making a String-贪心/set
- maven+springMVC+mybatis+junit详细搭建过程
- 我会的东西
- 基本算法——第九单元 递推
- NativeActivity的胶水层android_native_app_glue详解和使用
- HDU 1029 Ignatius and the Princess IV
- VS2013下socket新函数代替旧函数引起的编译错误