Android中Intent主要分为显式Intent和隐式Intent,今天会主要讲隐式Intent
一、显式Intent
最常用的就是下面这种形式

Intent intent = new Intent(FirstActivity.this, Second.class);startActivity(intent);

二、隐式Intent
这种Intent方式主要是通过action和category来由系统分析该启动哪一个活动
1、指定action

AndroidManifest.xml中

<activity android:name=".WelcomeActivity">      <intent-filter>          <action android:name="com.bingjian.ACTION_START" />          <category android:name="android.intent.category.DEFAULT" />      </intent-filter></activity>
Intent intent = new Intent("com.bingjian.ACTION_START");startActivity(intent);

只有指定的actioncategory同时匹配才会响应该活动,上面的代码在启动时之所以没有指定category是因为android.intent.category.DEFAULT是一直默认的category,会在startActivity时默认杯添加到intent中。

2、指定action和category

<activity android:name=".WelcomeActivity">      <intent-filter>          <action android:name="com.bingjian.ACTION_START" />          <category android:name="com.bingjian.MY_CATEGORY" />      </intent-filter></activity>
Intent intent = new Intent("com.bingjian.ACTION_START");intent.addCategory("com.bingjian.MY_CATEGORY");startActivity(intent);

3、启动其他程序的活动

Intent intent = new Intent("Intent.ACTION_VIEW");intent.setData(Uri.parse("http://www.qq.com"));startActivity(intent);

上面的代码会调用浏览器打开http://www.qq.com

4、在标签中配置data标签

data标签中主要可以配置以下内容

  • android:scheme 用来指定数据的协议部分
  • android:host 用于指定数据的主机名部分
  • android:port 指定数据的端口
  • android:path 指定主机名和端口之后的部分
  • android:mimeType 指定可以处理的数据类型,可以使用通配符

常用的数据协议
- http协议
- geo 地理位置
- tel 拨打电话

更多相关文章

  1. 几个标签属性的意义
  2. Android使用SQLite数据库的示例
  3. Android 数据库SQLite的操作总结
  4. Android中利用Intent传递数据到另一个页面
  5. android 如何从sqlite读取数据到spinner下拉中显示
  6. android中的Sqlite数据库操作
  7. Android用surface直接显示yuv数据
  8. 【Android】HTTP请求远端String和byte[]数据

随机推荐

  1. Android无法调用JS的问题解决
  2. 【Android(安卓)开发教程】ListFragment
  3. Android调用WIFI设置
  4. Android中通过经纬度来过去到城市名称
  5. 编写android jni代码时遇到的问题
  6. Android关于 https SSL handshake aborte
  7. Android 中Handler
  8. android textview属性
  9. Android当中layer-list使用
  10. [Android] 布局基础知识点