tip8——intent的7个属性
来源:互联网 发布:如何开通淘宝达摩盘 编辑:程序博客网 时间:2024/06/05 07:03
1.显式意图,Component属性
//通过组件名称直接查找组件(通过component属性 Intent intent1 = new Intent(); ComponentName componentName = new ComponentName(this,Main9Activity.class); intent1.setComponent(componentName); //第二种写法// Intent intent = new Intent(this,Main9Activity.class); //第三种写法// Intent intent = new Intent(); // intent.setClass(HelloActivity.this, OtherActivity.class); startActivity(intent1);
2.Action属性
//使用间接法(通过action属性 //在配置文件中,在未有分类时,category必须要有默认的 Intent intent2 = new Intent(); intent2.setAction("com.example.john.action"); startActivity(intent2);
在配置文件中:
category的默认属性必须要有,不然会报错
<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
3.Category属性
//使用间接法,(通过action属性和category属性 //虽然这里自己添加了category,但是配置文件中默认的category必须要写上,不然还是会报错 Intent intent3 = new Intent(); intent3.setAction("com.example.john.action"); intent3.addCategory("com.example.john.category"); startActivity(intent3);
在配置文件中:
<intent-filter> <action android:name="com.example.john.action" /> <category android:name="com.example.john.category" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter>
4.data属性
//data属性,通常与action一起使用(是最常见的使用 Intent intent4 = new Intent(); intent4.setAction("android.intent.action.VIEW"); Uri data = Uri.parse("http://www.baidu.com"); intent4.setData(data); startActivity(intent4);
在配置文件中:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="www.baidu.com" android:scheme="http" /> </intent-filter>
5.type属性
//type属性,表示数据的类型 //setData()会把type设为空,setType()会把data设置为空 Intent intent5 = new Intent(); intent5.setAction("android.intent.action.VIEW"); Uri data2 = Uri.parse("http://www.baidu.com"); //setData()和setType()不能一起用,要同时设置的话就要用setDatatAndType()来设置Data的type intent5.setDataAndType(data2,"text/html"); startActivity(intent5);
在配置文件中:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="www.baidu.com" android:mimeType="text/html" android:scheme="http" /> </intent-filter>
6.Extras属性
//跳转页面时的数据存储// Intent intent = new Intent(this,MainActivityB.class);// Bundle bundle = new Bundle();// String s = et_text.getText().toString();// bundle.putString("string",s);// //把Bundle存入Intent// intent.putExtra("data",bundle);// startActivity(intent);
7.Flag属性
//Flag属性,常用的有4个 //FLAG_ACTIVITY_CLEAR_TOP //FLAG_ACTIVITY_NEW_TASK //FLAG_ACTIVITY_NO_HISTORY //FLAG_ACTIVITY_SINGLE_TOP Intent intent7 = new Intent(this,Main9Activity.class); intent7.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent7);
0 0
- tip8——intent的7个属性
- Intent的属性-Component属性
- Intent属性的设置
- Intent属性的设置
- Intent的属性
- Intent的Flag属性
- Intent 的四大属性
- Intent 属性的作用
- Intent的属性
- Intent的属性
- Intent的七大属性
- Intent的七大属性
- Intent的七大属性
- Intent的七大属性:
- Intent的七大属性
- Intent属性的设置
- Intent的七大属性
- Android的Intent&IntentFilter Intent属性及Intent-filter配置
- android高德定位使用
- SLIC超像素分割详解
- MyBatis延迟加载
- loadrunner添加服务器监控
- Java 查找指定文件夹下的所有文件中包含有中文的文件,并抠出中文
- tip8——intent的7个属性
- 将字符串按照传入的参数进行逆序
- Linux常用命令行3
- CALayer(二)
- EasyRMS 详细介绍
- Ducci Sequence UVA
- input标签上传图片到后端前用H5的FileReader 方法实现图片的显示
- ValuceCK
- TLE二行轨道根数格式