一:显式调用  需要明确指定被启动对象的组件信息,一般是在相同的应用程序内部实现的

Intent intent = new Intent();

intent.setClass(SecondActivity.this,ThirdActivity.class);

startActivity(intent);

二:隐式调用:

  通过Intent Filter来实现的,它一般用在没有明确指出目标组件名称的前提下。Android系统会根据隐式

意图中设置的动作(action)、类别(category)、数据(URI和数据类型)找到最合适的组件来处理这个意图(只有三个

三个字段都匹配成功了才会启动目标Activity)。一般是用于在不同应用程序之间。

 

Action字段:

  1、Intent中action能够和过滤规则中的任何一条相同可匹配成功

  2、如果对应的Activity中action字段没有定义数据,则为匹配不成功。

  3、action区分大小写

category字段:

  1、Intent中action能够和过滤规则中的任何一条相同可匹配成功

  2、如果intent中没有添加Catrgory字段,那么intent中会有一个默认的category字段:android.intent.category.DEFAULT

这就需要在陪陪规则里面添加 该项 category值:如下代码中。

data字段:

<activity
Android:name="com.ryg.chapter_1.ThirdActivity"
android:configChanges="screenLayout"
android:label="@string/app_name"
android:launchMode="singleTask"
android:taskAffinity="com.ryg.task1" >
<intent-filter>
<action android:name="com.ryg.charpter_1.c" />
<action android:name="com.ryg.charpter_1.d" />
<category android:name="com.ryg.category.c" />
<category android:name="com.ryg.category.d" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>

 三、PendingIntent

   intent英文意思是意图,pending表示即将发生或来临的事情。  PendingIntent这个类用于处理即将发生的事情。比如在通知Notification中用于跳转页面,但不是马上跳转。

  在Android开发中,PendingIntent主要用于Notification、AlarmManager以及Widget中,获取PendingIntent主要有三种方式:getActivity(),getService()以及getBroadcast()。

  Intent 是及时启动,intent 随所在的activity 消失而消失。 
  PendingIntent 可以看作是对intent的包装,通常通过getActivity,getBroadcast ,getService来得到pendingintent的实例,当前activity并不能马上启动它所包含的intent,而是在外部执行 pendingintent时,调用intent的。正由于pendingintent中 保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行pendingintent里的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。另外还可以处理intent执行后的操作。

常和alermanger 和notificationmanager一起使用。

  Intent一般是用作Activity、Sercvice、BroadcastReceiver之间传递数据,而Pendingintent,一般用在 Notification上,可以理解为延迟执行的intent,PendingIntent是对Intent一个包装。

下面是一个通知栏显示中运用到的PendingIntent:

 public void testPendingIntent(View v){
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setSmallIcon(R.drawable.gps_point);
mBuilder.setContentTitle("My notification");
mBuilder.setContentText("Hello World!");
Intent resultIntent = new Intent(this, PendingIntentResult.class);
//获取pendingIntent,并设进
PendingIntent resultPendingIntent = PendingIntent.getActivity(this,0,resultIntent,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}

发送短信中的应用:

String msg ="你好,美女";
String number = "135****6784";
SmsManager sms = SmsManager.getDefault(); PendingIntent pi = PendingIntent.getBroadcast(SmsActivity.this,0,new Intent(...),0);
sms.sendTextMessage(number, null, msg, pi, null);
Toast.makeText(SmsActivity.this,"发送成功",Toast.LENGHT_LONG).show();

代码解释 
      PendingIntent就是一个Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的别的时间做你安排做的事情 (By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself,就相当于PendingIntent代表了Intent)。本例中别的程序就是发送短信的程序,短信发送成功后要把intent广播出去 。 
      函数SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)中参数解释: 
      1)PendingIntent sentIntent:当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,否则产生错误代码并通过android.app.PendingIntent.OnFinished进行回调,这个参数最好不为空,否则会存在资源浪费的潜在问题; 
      2)PendingIntent deliveryIntent:是当消息已经传递给收信人后所进行的PendingIntent广播。 
      查看PendingIntent 类可以看到许多的Send函数,就是PendingIntent在进行被赋予的相关的操作。

参考:https://yq.aliyun.com/articles/32777

http://www.cnblogs.com/liyiran/p/4656821.html

Android IntentFilter匹配规则的更多相关文章

  1. Android IntentFilter 匹配原则浅析

    1 Intent分为两大类,显式和隐式. 显式事件,就是指通过 component Name 属性,明确指定了目标组件的事件. 比如我们新建一个Intent,指名道姓的说,此事件用于启动名为" ...

  2. Android开发——IntentFilter的匹配规则

    1.  IntentFilter中的过滤信息 启动Activity分为显式调用和隐式调用,前者没什么好讲的,后者需要Intent能够匹配目标组件的IntentFilter中所设置的过滤信息.包括act ...

  3. 【Android - 组件】之IntentFilter的匹配规则

    我们知道,Activity的启动模式分为两种,分别是显式启动和隐式启动.显式启动需要明确的指定被启动的对象的组件信息,包括包名和类名:而隐式启动需要 Intent 能够匹配目标组件的 IntentFi ...

  4. Android中的Intent Filter匹配规则介绍

    本文主要介绍了隐式Intent匹配目标组件的规则,若有叙述不清晰或是不准确的地方希望大家指出,谢谢大家: ) 1. Intent简介 Intent用于在一个组件(Component,如Activity ...

  5. 《Android开发艺术探索》读书笔记之IntentFillter的匹配规则

    使用intent启动不同组件的方法 组件类型 启动方法 Activity startActivity(Intent intent) startActivityForResult(Intent inte ...

  6. android IntentFilter 使用之 data过滤

    1 Intent分为两大类,显式和隐式. 显式事件,就是指通过 component Name 属性,明确指定了目标组件的事件. 比如我们新建一个Intent,指名道姓的说,此事件用于启动名为" ...

  7. Intent 匹配规则

    1.在AndroidManifest.xml中可以为 每个 Activity,Service 设置多个Intent-Filter; 在系统启动和程序安装之后,android会收集AndroidMani ...

  8. 05-IntentFilter的匹配规则

    IntentFilter的匹配规则 原则上一个Intent不应该既是显示调用又是隐式调用,如果二者共存的话以显式调用为主 隐式调用需要Intent能够匹配目标组件的IntentFilter中所设置的过 ...

  9. Android 代码混淆规则

    1. Proguard介绍 Android SDK自带了混淆工具Proguard.它位于SDK根目录toolsproguard下面.ProGuard是一个免费的Java类文件收缩,优化,混淆和预校验器 ...

随机推荐

  1. 全球晶圆代工厂哪家强?2016年Top30名单

    1.台积电(TSMC) 总部:台湾 简介:世界上最大的独立半导体晶圆代工企业,与联华电子并称“晶圆双雄”. 主要客户:苹果,高通,联发科,华为海思 官网:http://www.tsmc.com/ 2. ...

  2. Linux必须学的东西,鉴于各大公司实际开发都不用Windows系统

    Windows安全性比较差,所以各大公司会使用其他的平台,所以像Linux就是很常用的,基于Unix的开源系统,鉴于很多人写的很散,所以自己总结下对于自己有用的重点,现在总结下简单的linxu的命令使 ...

  3. day3之装饰器

    1.什么是装饰器? #在不改变原函数的调用的情况下,为原函数增加一些额外的功能,打印日志,执行时间,登录认证 2.装饰器的形成过程 # 需求写一个函数测试另一个函数的执行效率 最初的实现方式,但是改变 ...

  4. (KMP 水)Wow! Such Doge! -- hdu -- 4847

    http://acm.hdu.edu.cn/showproblem.php?pid=4847 Wow! Such Doge! Time Limit:1000MS     Memory Limit:32 ...

  5. DDA_为微分绘制直线算法

    DDA_为微分绘制直线算法 以步进坐标轴部长=1像素为单位,计算y=kx + b,绘制像素点(x, round(y)). 即步进坐标增长1, 另一坐标增长K或者1/k. 程序如下: //数值微分算法D ...

  6. hdu 5066 小球碰撞(物理题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5066 中学物理题 #include <cstdio> #include <cstdlib> ...

  7. hdu 4994 前后有序Nim游戏

    http://acm.hdu.edu.cn/showproblem.php?pid=4994 Nim游戏变成从前往后有序的,谁是winner? 如果当前堆数目为1,玩家没有选择,只能取走.遇到到不为1 ...

  8. Bellman_ford货币兑换——正权回路判断

    POJ1860 题目大意:你在某一点有一些钱,给定你两点之间钱得兑换规则,问你有没有办法使你手里的钱增多.就是想看看转一圈我的钱能不能增多,出现这一点得条件就是有兑换钱得正权回路,所以选择用bellm ...

  9. Eclipse技巧

    1 alt + / 提示 2 ctrl + shift + g 查找方法被谁调用 3 ctrl + t 查看某个类的继承关系 4 alt + 上/下 移动当前行上或者下 5 ctrl + / 行注释 ...

  10. [mobile]移动端页面没有重新请求时,刷新页面代码

    <input type="hidden" value="yes" id="id_if_reload" /> <script ...