Intents and Intent Filters---序言

Intents and Intent Filters

Key classes

   1. Intent
   2. IntentFilter
   3. Activity
   4. Service
   5. BroadcastReceiver
   6. PackageManager

本文中将包含以下内容:

   1. Intent Objects
   2. Intent Resolution
   3. Intent filters
   4. Common cases
   5. Using intent matching
   6. Note Pad Example

   Three of the core components of an application — activities, services, and broadcast receivers — are activated through messages, called intents. Intent messaging is a facility for late run-time binding between components in the same or different applications. The intent itself, an Intent object, is a passive data structure holding an abstract description of an operation to be performed — or, often in the case of broadcasts, a description of something that has happened and is being announced. There are separate mechanisms for delivering intents to each type of component:

翻译:在Android系统中有三类核心组件 activities, services, broadcast receivers。这些组件都是通过一个称之为intent的消息对象激活的。intent消息对象可以理解是应用程序或应用程序之间组件的链接或绑定工具。intent消息对象本身只是一个抽象数据结构体对象,其中包含的信息是对某种操作的描述。针对所要激活的组件类型的不同,发送相应的intent 对象的方式也分以下三种。(intent这个词我个人理解还是不要翻译出来为好,把它理解成与HttpRequest类似的请求对象既可。)

    一、An Intent object is passed to Context.startActivity() or Activity.startActivityForResult() to launch an activity or get an existing activity to do something new. (It can also be passed to Activity.setResult() to return information to the activity that called startActivityForResult().)【翻译:Intent对象作为Context.startActivity() 或 Activity.startActivityForResult()方法的参数,可以在方法执行的时候让系统创建并启动一个activity实例或是使得一个现存的activity实例响应该intent请求,执行相关的操作(Intent对象也是Activity.setResult()方法的参数,该方法与startActivityForResult()方法有前后依赖关系,目标activity可以向源activity返回intent对象的,实际需要的返回值被封装在原始intent实例中被返回)】。

    二、An Intent object is passed to Context.startService() to initiate a service or deliver new instructions to an ongoing service. Similarly, an intent can be passed to Context.bindService() to establish a connection between the calling component and a target service. It can optionally initiate the service if it's not already running.
      【翻译:Context.startService()方法的参数intent的目的是创建一个服务组件实例或是给一个执行中的服务实例发送指令,同样, Context.bindService()的参数intent的作用是在当前组件与目标服务之间创建一个连接,如果说目标服务没有启动,那么将会创建目标服务组件实例。】

    三、Intent objects passed to any of the broadcast methods (such as Context.sendBroadcast(), Context.sendOrderedBroadcast(), or Context.sendStickyBroadcast()) are delivered to all interested broadcast receivers. Many kinds of broadcasts originate in system code.【翻译:intent对象也是众多广播方法如Context.sendBroadcast(), Context.sendOrderedBroadcast(), 或 Context.sendStickyBroadcast()的参数,这个参数同样也是被传递给广播接收组件的,在Android系统代码中,有很多类型的广播接收组件。】

In each case, the Android system finds the appropriate activity, service, or set of broadcast receivers to respond to the intent, instantiating them if necessary. There is no overlap within these messaging systems: Broadcast intents are delivered only to broadcast receivers, never to activities or services. An intent passed to startActivity() is delivered only to an activity, never to a service or broadcast receiver, and so on.

【翻译:以上我们说到的场合,Android系统会查找目标activity或目标service或是相关的那些广播接收器组件来对当前 intent实例做应答,如果说需要,那么系统会创建相应的组件实例,系统在定位目标组件的时候不会出现重复定位的现象,不同类别的目标组件会被严格区分。】

This document begins with a description of Intent objects. It then describes the rules Android uses to map intents to components — how it resolves which component should receive an intent message. For intents that don't explicitly name a target component, this process involves testing the Intent object against intent filters associated with potential targets.

【翻译:该文档开始介绍intent消息对象。同时还将就Android系统对intent实例和目标组件之间的匹配规则以及intent消息对象如何被解析、匹配到一个目标组件的详细过程做描述。尤其针对隐式intent消息对象,对Android系统基于intent过滤器寻找目标组件的匹配测试过程作详细说明。】

你可能感兴趣的:(数据结构,应用服务器,android)