Android -- 两个activity界面的切换, 显示Intent 和 隐式Intent,putExtra传递数据
1. 两个Activity之间可以通过Intent切换, 包括显示Intent 和 隐式Intent。
实例代码
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/*
同一个应用程序里面 自己激活自己的东西. 推荐使用显示意图. 效率高.
不同的应用程序里面,激活别人的应用,或者是让自己的某一个界面希望被别人激活,推荐使用隐式意图,
1. 查询系统里面的所有的activity 看看是不是有满足条件的activity.
2.有,判断多少个,只有1个 直接启动, 如果有多个,列表方式
3.如果没有, 应用程序异常终止 activity not found execption
*/
// Intent 显示意图.
// 显示意图: 必须要指定开启组件的具体信息( 包名, 组件名, 组件的class)
//当用户点击按钮的时候 跳转到第二个界面
public void click(View view){
Intent intent = new Intent(this, OtherScreenActivity.class);
// intent.setClassName(this, "com.itheima.twoactivity.OtherScreenActivity");
startActivity(intent);
}
public void click2(View view){
//cmp=com.android.gallery/com.android.camera.GalleryPicker
Intent intent = new Intent();
intent.setClassName("com.android.gallery", "com.android.camera.GalleryPicker");
startActivity(intent);
}
//采用隐式意图 激活第三个界面
public void click3(View view){
Intent intent = new Intent();
intent.setAction("com.itheima.xxx");
//如果权限xml文件中没有加,则是默认值,必须设置为CATEGORY_DEFAULT
intent.addCategory(Intent.CATEGORY_DEFAULT);
//指定数据的类型, 如果一个APP既有Data又有Type 必须同时设置
//intent.setType("vnd.android.cursor.item/haha");
//intent.setData(Uri.parse("itheima:gagaga"));
intent.setDataAndType(Uri.parse("itheima:gagaga"), "vnd.android.cursor.item/haha");
intent.putExtra("name", "kevin");
//putExtra 可以传对象,但是需要实现Serializable接口
startActivity(intent);
//动作action 类型Type 数据data
//动作 数据
//打 人 打酱油
//泡 茶 泡 妞
//泡绿茶 泡红茶 泡乌龙茶
//addCategory 附加的信息. 提供一些执行的环境 参数
}
public void click4(View view){
Intent intent = new Intent();
intent.setAction("android.intent.action.SENDTO");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("sms:110"));
startActivity(intent);
}
}
OtherScreenActivity.java
//activity 是系统的重要的组件 ,
//操作系统要想找打activity 就必须在 清单文件里面配置
public class OtherScreenActivity extends Activity {
//重写 activity 的oncreate方法 方法里面设置初始化程序的界面.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two); Intent intent = getIntent();//获取到激活他的意图
Uri uri = intent.getData();
String result = uri.toString();
String name = intent.getStringExtra("name");
System.out.println(result);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima.twoactivity"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" /> <application
android:allowBackup="true"
android:icon="@drawable/app"
android:label="@string/application_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.itheima.twoactivity.MainActivity"
android:icon="@drawable/atools"
android:label="@string/activiy01" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <activity
android:name="com.itheima.twoactivity.OtherScreenActivity"
android:icon="@drawable/ic_scanner_malware"
android:label="@string/activity02" >
<intent-filter>
<action android:name="com.itheima.xxx" /> <data
android:mimeType="vnd.android.cursor.item/haha"
android:scheme="itheima" >
</data> <category android:name="android.intent.category.DEFAULT" >
</category>
</intent-filter>
</activity>
</application> </manifest>
Android -- 两个activity界面的切换, 显示Intent 和 隐式Intent,putExtra传递数据的更多相关文章
- Android开发学习笔记:浅谈显示Intent和隐式Intent
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://liangruijun.blog.51cto.com/3061169/655132 ...
- Android开发学习之浅谈显示Intent和隐式Intent
Intent寻找目标组件的两种方式: 显式Intent:通过指定Intent组件名称来实现的,它一般用在知道目标组件名称的前提下,一般是在相同的应用程序内部实现的. 隐式Intent:通过Intent ...
- 在Android中Intent的概念及应用(一)——显示Intent和隐式Intent
Intent寻找目标组件的两种方式: 显式Intent:通过指定Intent组件名称来实现的,它一般用在知道目标组件名称的前提下,一般是在相同的应用程序内部实现的. 隐式Intent:通过Intent ...
- 【Android】6.0 添加Menu菜单组件、Intent启动活动、显式Intent、隐式Intent
1.0 在helloworld项目基础上创建活动SecondActivity: 2.0 其中main.xml: <?xml version="1.0" encoding=&q ...
- 2018.7.9 Android—显式Intent和隐式Intent的区别
1:都是用来在一个activity中启动另外一个activity 2:显示Intent直接指明要启动activity的定义,即activity.class:隐式intent通过在androidmani ...
- selenium 显示等待、隐式等待、强制等待
如今大部分web程序使用Ajax技术,当浏览器加载页面时,页面元素可能不是同时加载完成,如果因为加载某个元素超时导致ElementNotVisibleException的情况出现,自动化脚本的稳定性就 ...
- 显示intent和隐示intent有什么区别
显式Intent定义:对于明确指出了目标组件名称的Intent,我们称之为显式Intent. 隐式Intent定义:对于没有明确指出目标组件名称的Intent,则称之为隐式Intent. 说明:And ...
- Android学习记录(7)—Intent中显示意图和隐式意图的用法
Intent(意图)主要是解决Android应用的各项组件之间的通讯. Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述,Android则根据此Intent的描述,负责找到对应的 ...
- Android 显示意图和隐式意图的区别
意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么. 意图的作用: 1.激活组件 ...
随机推荐
- 七个可以提升python程序性能的好习惯,你知道吗?
掌握一些技巧,可尽量提高Python程序性能,也可以避免不必要的资源浪费.今天就为大家带来七个可以提升python程序性能的好习惯,赶快来学习吧:. 1.使用局部变量 尽量使用局部变量代替全局变量:便 ...
- Java-工程中常用的程序片段
1.字符串-整型相互转换 String s = String.valueOf(2); int a = Integer.parseInt(s); 2.向文件末尾添加内容 BufferedWriter b ...
- mysql 数据库查询最后两条数据
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011925175/article/details/24186917 有一个mysql数据库的 ...
- Linux PHP7的openssl扩展安装
Linux环境下使用PHPmailer发送邮件时,出现如下错误: SMTP -> ERROR: Failed to connect to server: Unable to find the s ...
- mysql构建一张百万级别数据的表信息测试
表信息: CREATE TABLE dept( /*部门表*/ deptno MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, /*编号*/ dname VARCHAR(2 ...
- 宏表达式与函数、#undef、条件编译、
宏表达式在预编译期被处理,编译器不知道宏表达式的存在. 宏表达式没有任何的调用开销 宏表达式中不能出现递归定义. C语言中强大的内置宏 __FILE__:被编译的文件名 //双底线 __LINE__: ...
- 子集和问题(应用--换零钱)POJ2229:Sumsets
我一直在纠结换零钱这一类型的题目,今天好好絮叨一下,可以说他是背包的应用,也可以说他是单纯的dp.暂且称他为dp吧. 先上一道模板题目. sdut2777: 小P的故事——神奇的换零钱 题目描述 已知 ...
- 以About Us为范例在Zen cart中增加页面
1.在includes\languages\english\html_includes目录中新建文件define_about_us.php 2.在includes\templates\Your_tem ...
- ionic 配置打包环境
配置java环境就不说了,太简单 下载AndroidSdkAndroid SDK Tools翻过墙的朋友可以去Google Android的官网上下载:http://developer.android ...
- selenium 之定位方法
1 id 定位 driver.find_element_by_id() HTML 规定id 属性在HTML 文档中必须是唯一的.这类似于公民的身份证号,具有很强的唯一性 from selenium i ...