Intent学习

Intent分为两种显式意图和隐式意图,

1.显式意图

主要用于已经知道要跳转的组件的名字的情况下

使用代码如下:

// intent 意图 , 描述一个动作, 激活一个组件

/*第一种写法

* Intent intent = new Intent();

intent.setClassName("cn.itcast.mutileactivity", "cn.itcast.mutileactivity.Demo2Activity");*/

// 第二种写法

//Intent intent = new Intent(this,Demo2Activity.class);

/*

*第三种写法

Intent intent = new Intent();

compnentName :包名+组件名字

ComponentName component = new ComponentName("cn.itcast.mutileactivity", "cn.itcast.mutileactivity.Demo2Activity");

intent.setComponent(component);

*/

2.隐式意图

主要用于不知道要跳转的组件的名字情况下,通常情况下是使用另外一个应用的一些组件,比如在自己的应用打开通讯录等等.

代码如下:

//****************************************************

// Intent intent = new Intent();

// intent.setAction("cn.itcast.mutileactivity.xxx");

// intent.addCategory("android.xxx");

// intent.setData(Uri.parse("itcast://cn.itcast.demo"));

//intent.setType(type); // mime 数据类型 image/jpeg

// 隐式意图

// 只需要指定 intent的动作 ,intent的数据

// 如果我们想激活另外一个应用程序的组件

// Intent intent = new Intent();

// intent.setAction(Intent.ACTION_PICK);

//

// intent.setType("image/jpeg");

// intent 要去做一件事 泡 动作 泡茶 泡咖啡 泡妞 打人 打酱油

// intent.setData();指定数据的类型 type

// intent.addCategory();

/**

* <intent-filter>

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />

<data android:mimeType="vnd.android-dir/mms-sms" />

</intent-filter>

*/

/* Intent intent = new Intent();

intent.setAction(Intent.ACTION_VIEW);

intent.addCategory("android.intent.category.DEFAULT");

intent.setType("vnd.android-dir/mms-sms");*/

/**

* <intent-filter>

<action android:name="android.intent.action.VIEW" />

<action android:name="android.intent.action.SENDTO" />

<category android:name="android.intent.category.DEFAULT" />

<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="sms" />

<data android:scheme="smsto" />

</intent-filter>

*/


更多相关文章

  1. Android架构组件(2)LifecycleRegistry 源码分析
  2. Android(安卓)Activity和Intent机制学习笔记
  3. android ListView的滑动效率问题
  4. Android有用的工具类:倒计时器、 ViewHolder简化写法
  5. template class build errors in android
  6. 【Android】10.1 扩展组件库和其他视图--本章示例主界面
  7. Android开发环境配置之ADT怪异问题
  8. Intent学习
  9. 组件(Widget)的复合使用

随机推荐

  1. Android获取本机蓝牙地址
  2. Error:Android Source Generator: Cannot
  3. Gradle:Android打包动态传参及多productFl
  4. BadgeView 与 RadioButton
  5. Android 设备管理器和有权查看使用情况的
  6. Android 软键盘盖住输入框的问题
  7. android 手机滤镜
  8. android HorizontalScrollView实现滚动监
  9. android自定义属性之format介绍
  10. Android - Jar mismatch! Fix your depen