Android Intent全解析

Intent

Intent 可以携带的数据类型

八种基本数据类型boolean、byte、char、short、int、float、double、long 和String 以及这9 种数据类型的数组形式

实现了Serializable 接口的对象

实现了Android 的Parcelable 接口的对象以及其数组对象

Activity使用Intent跳转

显式

Intent intent = new Intent();		//通过字节码,或者包名+类名的方法实现的跳
intent.setClass(this, SecondActivity.class);
startActivity(intent);

隐式

1 在有跳转需求的AndroidMainfest.xml --> activity --> 配置intent-filter
	<intent-filter >
		<action android:name="自己定义,习惯用包名后加功能名"/>
		<category android:name="android.intent.category.DEFAULT"/> 	
	</intent-filter>
2 跳转到的目标页面,activity代码:
	Intent intent = new Intent();
	intent.setAction("上面<action/>中android:name字符串");
	intent.addCategory("android.intent.category.DEFAULT");		//与上面对应
	startActivity(intent);

	setAction只需指定一个
	category 至少匹配一个
	data 至少匹配一个
	//原清单文件:<data android:scheme="http" />
	intent.setData(Uri.parse("http://www.tangheng.com"));
注意(隐式):MainActivity清单文件中intent-filter中可配置多个data标签
	<data android:scheme="自己定义"/> -->设置前缀
	<data android:authority="一般为自己包名"/>
	//path可用pathPattern代替,意为模糊匹配
	<data android:path=""/>
	//type也可为mineType
	<data android:Type="text/plain"/> -->定义类型,这里不能随意定义,例如file,text等
data标签在跳转目标页面activity代码配置
	如果同时配置了scheme和mineType		intent.setDataAndType(scheme,mimeType);
	如果只配置scheme					intent.setData();
	如果只配置了mimeType				intent.setType();

猜你喜欢

转载自blog.csdn.net/mLuoya/article/details/87927187