android intent深入解析
16lz
2022-05-30
一.Intent的显示调用:
// 1 intent.setClass(this, OtherActivity.class);// 2intent.setClassName(this, "com.zizhu.activitys.OtherActivity");// 3intent.setComponent(new ComponentName(this, OtherActivity.class));// 4Intent intent = new Intent(this, OtherActivity.class); intent.setClassName("com.zizhu.activitys", "com.zizhu.activitys.OtherActivity");//这个方法可以激活其他应用的Activity
二.intent的隐式调用:
public void openOtherActivity(View view){ /** * 只要Intent中的action和category都出现在 意图过滤器中,都能与之匹配,否则匹配不成功 * 另外,如果manifest文件中配置了action, category, data等内容,intent必须都要匹配才能激活,如果只匹配一部分是不能激活的 */ Intent intent = new Intent(); intent.setAction("com.zizhu.other"); intent.addCategory("com.zizhu.category.android"); intent.addCategory("android.intent.category.DEFAULT"); intent.setDataAndType(Uri.parse("zizhu://www.zizhu.com"), "image/jpeg");//如果既设置了mineType,也设置了data,必须用这个方法// intent.setData(Uri.parse("zizhu://www.zizhu.com"));// intent.setType("image/jpeg");//这个方法会自动清除设置了data的内容 startActivity(intent);//这个方法会自动添加category为 andriod.intent.category.DEFAULT,所以在配置文件中需要添加这个category }
manifest配置文件:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.zizhu.intent" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".OtherActivity" android:label="@string/other" > <intent-filter> <action android:name="com.zizhu.other" /> <category android:name="com.zizhu.category.android" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="zizhu" android:host="www.zizhu.com" /> <data android:mimeType="image/*"></data> </intent-filter> </activity> </application></manifest>
更多相关文章
- Android(安卓)设置全屏显示的方法
- android百度地图 SDK v3.5.0
- Android中对话框的工具类
- android设置一个图片为全屏大小
- Android(安卓)HttpGet和HttpPost设置超时
- android网络连接
- Android(安卓)网络连接-重试机制-HttpRequestRetryHandler(HttpCl
- Android动态设置控件高度
- 第一章:初入Android大门(程序加载应用)