WEB开发网
开发学院手机开发Android 开发 Android 开发文档 程序基础——Intent filters 阅读

Android 开发文档 程序基础——Intent filters

 2010-06-17 03:20:00 来源:WEB开发网   
核心提示:Intent对象可以明确命名一个目标组件,如果这么做了,Android 开发文档 程序基础——Intent filters,Android会找到组件并激活,但是如果目标并没有明确的命名,由于broadcast receiver在代码中创建和注册,所以intent filter被直接作为InterFilter对象,And

Intent对象可以明确命名一个目标组件。如果这么做了,Android会找到组件并激活。但是如果目标并没有明确的命名,Android必须定位一个最好的组件并反馈给intent。这是通过与可能的目标的Intent filters进行对比做到的。一个组件的intent filter告诉android组件可以处理的intents的种类。

一个组件可以有许多intent filters,每一个都定义一个不同的功能。如果没有intent filters,那么就只能通过明确命名组件为目标的方法来激活。

由于broadcast receiver在代码中创建和注册,所以intent filter被直接作为InterFilter对象。其他的filters都在manifest中建立。

原文

Intent filters

An Intent object can explicitly name a target component. If it does, Android finds that component (based on the declarations in the manifest file) and activates it. But if a target is not explicitly named, Android must locate the best component to respond to the intent. It does so by comparing the Intent object to the intent filters of potential targets. A component’s intent filters inform Android of the kinds of intents the component is able to handle. Like other essential information about the component, they’re declared in the manifest file. Here’s an extension of the previous example that adds two intent filters to the activity:

< ?xml version=”1.0″ encoding=”utf-8″? >

< manifest . . . >

< application . . . >

< activity android:name=”com.example.project.FreneticActivity”

android:icon=”@drawable/small_pic.png”

android:label=”@string/freneticLabel”

. . . >

< intent-filter . . . >

< action android:name=”android.intent.action.MAIN” / >

< category android:name=”android.intent.category.LAUNCHER” / >

< /intent-filter >

< intent-filter . . . >

< action android:name=”com.example.project.BOUNCE” / >

< data android:mimeType=”image/jpeg” / >

1 2  下一页

Tags:Android 开发 文档

编辑录入:coldstar [复制链接] [打 印]
赞助商链接