Android学习之Intent中显示意图和隐式意图的用法实例分析

2019-12-10 19:55:43王冬梅

第二个Activity里的东西就是我们自定义设置的,就是下边的这段代码:

 

 
  1. <activity android:name="net.loonggg.intent.SecondActivity" >   <intent-filter>  
  2. <!-- 自定义的动作 -->  <action android:name="net.loonggg.xxx" />  
  3. <!-- 自定义的scheme和host -->  <data 
  4. android:host="www.baidu.com"  android:path="/person" 
  5. android:scheme="loonggg" />   <!-- 自定义的类型 --> 
  6. <data android:mimeType="person/people" />   <!-- 附加信息 --> 
  7. <category android:name="android.intent.category.DEFAULT" />   </intent-filter>  
  8. </activity> 

那在代码中怎么调用自定义的呢?其实跟调用系统短信一样,只不过调用系统短信里的那些动作和数据,系统已经给我们配置好了,我们直接用就行,而自定义的就是我们自己写的,调用方法和系统其实是一样的。方法如下:

 

 
  1. /**   * 通过自定义的隐式意图启动  
  2. *   * @param view  
  3. */  public void startTwo(View view) {  
  4. Intent intent = new Intent();   intent.setAction("net.loonggg.xxx");  
  5. intent.addCategory("android.intent.category.DEFAULT");   intent.setDataAndType(Uri.parse("loonggg://www.baidu.com/person"),