intent 跳转
一、不需要返回值的跳转
Intent intent=new Intent();
intent.setClass(目前的acitivy.this, 目标activity.class);
startActivity(intent);
二、需要返回值的跳转
Intent intent=new Intent();
intent.setClass(目前的acitivy.this, 目标activity.class);
startActivity(intent);
startActivityForResult(intent, 状态值(int类型));
状态值作为接受目标返回值的验证。
requestCode 接收返回的状态值
resultCode :RESULT_OK RESULT_CANCELED 可以自己赋值,按返回键时,系统默认赋值为:RESULT_CANCELED
目标activity 关闭才能返回请求activity
例如:
1、请求页面
public class MainActivy extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent=new Intent();
intent.setClass(MainActivy.this, ReceiveMSG.class);
startActivityForResult(intent, 0); //调用public void startActivityForResult (Intent intent, int requestCode)方法
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==0) {
if (resultCode==RESULT_OK) {
Toast.makeText(this, "Send SMS RESULT_OK", Toast.LENGTH_SHORT).show();
}else if (resultCode==RESULT_CANCELED) {
Toast.makeText(this, "result cancel", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this, resultCode, Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(this, "requsetcode not 0", Toast.LENGTH_SHORT).show();
}
}
}
2、接收返回值界面
public class ReceiveMSG extends Activity{
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ReceiveMSG.this.setResult(RESULT_OK);
this.finish();
}
}
intent 跳转的更多相关文章
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 1.跳转到拨号界面,代码如下: 1)直接拨打 Intent intentPhone = new Intent ...
- Intent 跳转Activity
Intent 跳转 显示跳转(用类名跳转) Intent i = new Intent(a.this,b.class); 隐士跳转 自定义Action <!--配置跳转Activity--> ...
- Android 隐式 Intent 跳转注意事项
前几天正好看到<阿里巴巴 Android 开发手册>中提到的: “Activity 间通过隐式 Intent 的跳转,在发出 Intent 之前必须通过 resolveActivity 检 ...
- Android搞事篇——使用Intent跳转界面
跳转页面基本分为三个步骤: 1.初始化一个intent:(一个intent就够用了): 2.传入intent参数: 3.调用startactivity();实现跳转页面 具体操作如下 首先你需要一个项 ...
- 安卓基础之通过Intent跳转Activity
通过Intent跳转Activity 一.通过意图开启Activity的方式: 隐式意图:通过指定一组数据或者动作实现 Intent intent=new Intent(); intent.s ...
- Android开发中使用Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 首先,我们先看拨号界面,代码如下: Intent intent =new Intent(); intent. ...
- [android]Intent跳转新的Activity可以传递数据过去
两种方式: 一,直接通过Bundle对象来传递: 如果我们想要给“收件人”Activity说点什么的话,那么可以通过下面这封“E-mail”来将我们的消息传递出去 Intent intent=new ...
- Intent跳转到系统应用中的拨号界面、联系人界面、短信界面及其他
现在开发中的功能需要直接跳转到拨号.联系人.短信界面等等,查找了很多资料,自己整理了一下. 首先,我们先看拨号界面,代码如下: Intent intent =new Intent(); intent. ...
- android intent 跳转
转自:http://blog.sina.com.cn/s/blog_7309444701014u2d.html 一.不需要返回值的跳转 Intent intent=new Intent(); inte ...
随机推荐
- .NET Core快速入门教程 3、使用VS Code开发.NET Core控制台应用程序
一.前言 本篇开发环境 1.操作系统: Windows 10 X642.SDK: .NET Core 2.0 Preview3.VS Code:1.14 二.安装&配置 1.VS Code下载 ...
- [SUCTF 2019]Pythonginx
贴出源码 @app.route('/getUrl', methods=['GET', 'POST']) def getUrl(): url = request.args.get("url&q ...
- 多进程 多进程queue
多进程 import multiprocessing import threading import time def thread_run(): print(threading.get_ident( ...
- main函数递归
以前听说main()不能递归?于是在CentOS7上使用gcc-8.1.0测试了一下,发现可行: #include <stdio.h> int x = 5; int main(int ar ...
- leetCode练题——20. Valid Parentheses
1.题目 20. Valid Parentheses——Easy Given a string containing just the characters '(', ')', '{', '}', ...
- Python实现图片识别加翻译【高薪必学】
Python使用百度AI接口实现图片识别加翻译 另外很多人在学习Python的过程中,往往因为没有好的教程或者没人指导从而导致自己容易放弃,为此我建了个Python交流.裙 :一久武其而而流一思(数字 ...
- 明明的随机数(0)<P2006_1>
明明的随机数 (random.pas/c/cpp) [问题描述] 明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中 ...
- char、pchar、string互相转换
1.string转换成pchar 可以使用pchar进行强制类型转换,也可以使用StrPCopy函数 var s:string; p,p1:PChar; begin s:='Hello Delphi' ...
- null值可以赋给引用变量,不能给基本类型
下面正确的写法是? cbyte i=128 boolean i=null long i=0xfffL double i=0.9239d null表示没有地址:null可以赋值给引用变量,不能将null ...
- .NET精彩博文
vs2019安装和使用教程(详细) 为什么选择.NETCore? C#中Socket的简单使用