Android 使用Intent 在Activity 间跳转
来源:互联网 发布:网络回合制游戏 编辑:程序博客网 时间:2024/05/22 00:29
假设有4个Activity: A,B,C,D
他们生成的顺序是: A->B->C->D
Activity之间的跳转,有几个方法:
1. startActivity,用于直接跳转
情景:从 A 跳转到 C:
Intent intent = new Intent(A.this, C.class);
startActivity(intent );
2. startActivityForResult,用于跳转之后,希望得到一个回应
情景:A跳转到B,B结束之后返回一个结果给A
2.1. Activity A的代码:
2.1.1. 跳转代码
Intent intent = new Intent(FriendActivity.this, TalkActivity.class);
int requestCode = 100;
intent.putExtra("param1",param1);
startActivityForResult(intent, requestCode);
2.1.2. 复写 onActivityResult
2.2. Activity B的代码:
Intent intent = new Intent();
intent.putExtra("data", data);
int resultCode = 100;
setResult(resultCode,intent);
3. 跳转到一个已经存在的Activity,避免已经存在的Activity 调用OnCreate()
情景:A跳转到B,B再跳转到C,等C结束之后,想直接跳转到A
3.1. 在跳转的地方(Activity C):
Intent intent = new Intent(C.this,A.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
3.2. 在AndroidManifest.xml 中将A的launchMode设置为“singleTop”
<activity android:name="A" android:launchMode="singleTop" />
3.3. 在Activity A 复写onNewIntent,将要特别处理的逻辑在这里处理
Reference:
http://stackoverflow.com/questions/2424488/android-new-intent-starts-new-instance-with-androidlaunchmode-singletop
- Android 使用Intent 在Activity 间跳转
- Android中的Handler+使用Intent进行Activity间的跳转
- Android学习笔记(四):在Activity中跳转--Intent的使用
- android在非Activity下,intent页面跳转问题
- Android 实例:在Activity 之间跳转的intent
- 使用Intent实现Activity跳转
- 自学Android之Activity:(三)使用Intent在Activity中跳转和传值(上)
- 自学Android之Activity:(四)使用Intent在Activity中跳转和传值(下)
- Android使用Intent实现Activity之间的跳转
- Android 使用Intent实现Activity跳转和数据传递
- android中使用intent来实现Activity带数据跳转
- Android基础之使用Intent实现Activity跳转
- Android使用intent跳转到其它应用activity界面
- Android使用Intent实现Activity之间的跳转
- Android使用intent跳转到其它应用activity界面
- Android-Adapter中使用Intent跳转到一个activity
- 用intent在activity之间跳转
- android用Intent实现Activity跳转
- 采用链地址法处理冲突构造哈希表
- Nginx和Tomcat安装记录
- JQuery基础核心
- hdu 4790 Just Random
- The things need to be done after installed Ubuntu
- Android 使用Intent 在Activity 间跳转
- POJ2251Dungeon Master&&nyoj523亡命逃窜
- 谷歌分析大数据怎么它就这么快?
- 如何使用st官网的库文件开发项目详细教程
- 調用webservice時出現HTTP狀態417:Expectation Failed的解決方法
- C#性能测试模板和洗牌的随机排序算法
- Recommended articles about graduate life
- el表达式
- Maximal Rectangle