Android 开发文档 程序基础——Intent filters
2010-06-19 10:54
459 查看
Intent对象可以明确命名一个目标组件。如果这么做了,Android会找到组件并激活。但是如果目标并没有明确的命名,Android必
须定位一个最好的组件并反馈给intent。这是通过与可能的目标的Intent filters进行对比做到的。一个组件的intent
filter告诉android组件可以处理的intents的种类。
一个组件可以有许多intent filters,每一个都定义一个不同的功能。如果没有intent
filters,那么就只能通过明确命名组件为目标的方法来激活。
由于broadcast receiver在代码中创建和注册,所以intent
filter被直接作为InterFilter对象。其他的filters都在manifest中建立。
转自我的android博客
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” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
</activity>
. . .
</application>
</manifest>
The first filter in the example — the combination of the action “android.intent.action.MAIN
”
and the category “android.intent.category.LAUNCHER
”
— is a common one. It marks the activity as one that should be
represented in the application launcher, the screen listing applications
users can launch on the device. In other words, the activity is the
entry point for the application, the initial one users would see when
they choose the application in the launcher.
The second filter declares an action that the activity can perform
on a particular type of data.
A component can have any number of intent filters, each one
declaring a different set of capabilities. If it doesn’t have any
filters, it can be activated only by intents that explicitly name the
component as the target.
For a broadcast receiver that’s created and registered in code, the
intent filter is instantiated directly as an IntentFilter
object. All other filters are set up
in the manifest.
For more on intent filters, see a separate document, Intents and
Intent Filters.
须定位一个最好的组件并反馈给intent。这是通过与可能的目标的Intent filters进行对比做到的。一个组件的intent
filter告诉android组件可以处理的intents的种类。
一个组件可以有许多intent filters,每一个都定义一个不同的功能。如果没有intent
filters,那么就只能通过明确命名组件为目标的方法来激活。
由于broadcast receiver在代码中创建和注册,所以intent
filter被直接作为InterFilter对象。其他的filters都在manifest中建立。
转自我的android博客
原文
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” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>
</activity>
. . .
</application>
</manifest>
The first filter in the example — the combination of the action “android.intent.action.MAIN
”
and the category “android.intent.category.LAUNCHER
”
— is a common one. It marks the activity as one that should be
represented in the application launcher, the screen listing applications
users can launch on the device. In other words, the activity is the
entry point for the application, the initial one users would see when
they choose the application in the launcher.
The second filter declares an action that the activity can perform
on a particular type of data.
A component can have any number of intent filters, each one
declaring a different set of capabilities. If it doesn’t have any
filters, it can be activated only by intents that explicitly name the
component as the target.
For a broadcast receiver that’s created and registered in code, the
intent filter is instantiated directly as an IntentFilter
object. All other filters are set up
in the manifest.
For more on intent filters, see a separate document, Intents and
Intent Filters.
相关文章推荐
- Android 开发文档 程序基础 ——Content providers组件
- Android 开发文档 程序基础——Activating components: intents
- Android 开发文档 程序基础——Shutting down components
- Android 开发文档 程序基础——The manifest file
- Android 开发文档 之程序基础Application Fundamentals
- Android 开发文档 程序基础 ——activity组件
- Android 开发文档 程序基础——Activities and Tasks
- Android 开发文档 程序基础 ——Services组件
- Android 开发文档 程序基础 ——Broadcast receivers组件
- Android 开发文档 程序基础——Affinities and new tasks
- android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果
- Android核心基础-3. 开发一个Android程序-3.2. 安装、卸载程序
- 14天学会安卓开发(第二天)Android程序设计基础activity和intent
- Android开发之旅: Intents和Intent Filters(理论部分)
- android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果
- Android简明开发教程七:Intents和Intent Filters
- Android开发之旅: Intents和Intent Filters(实例部分) 推荐
- android开发(26) 和其他应用交换数据方式一,使用intent指定自定义action调用其他程序里的activity,并获得其返回的结果
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
- Android开发指导文档(译)---Intent and Intent Fliter