Android 开发文档 程序基础——Intent filters
来源:互联网 发布:广西财经学院网络 编辑:程序博客网 时间:2024/05/19 16:21
Intent对象可以明确命名一个目标组件。如果这么做了,Android会找到组件并激活。但是如果目标并没有明确的命名,Android必须定位一个最好的组件并反馈给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 开发文档 程序基础——Intent filters
- android Intents和Intent Filters - 开发文档翻译 - 1
- [Android开发向导]Intents and Intent Filters
- android开发之Intents and Intent Filters
- Android(2)——Intents and Intent Filters
- Android 开发文档 程序基础 ——activity组件
- Android 开发文档 程序基础 ——Services组件
- Android 开发文档 程序基础 ——Broadcast receivers组件
- Android 开发文档 程序基础 ——Content providers组件
- Android 开发文档 程序基础——Activating components: intents
- Android 开发文档 程序基础——Shutting down components
- Android 开发文档 程序基础——The manifest file
- Android 开发文档 程序基础——Activities and Tasks
- 安卓基础——Intent与Intent Filters(阅读笔记)
- Android--Intent和Intent Filters
- Android学习笔记7——Intent和Intent Filters的介绍
- Android开发 之 Intents and Intent Filters(一)
- Android开发 之 Intents and Intent Filters(二)
- JQuery学习日志三(横向纵向菜单)
- Android 开发文档 程序基础——Activating components: intents
- Android 开发文档 程序基础——Shutting down components
- Oracle学习笔记(6) 动态SQL
- Android 开发文档 程序基础——The manifest file
- Android 开发文档 程序基础——Intent filters
- ListCtrl设置可写
- asp.net跳转页面的三种方法比较
- 网上看到的一篇DNS正向解析失败的问题解决方法
- 强烈推荐:240多个jQuery插件
- Oracle学习笔记(7) 开发PLSQL子程序和包
- Android 开发文档 程序基础——Activities and Tasks
- IPC in Linux
- 渐进式透明的设置(SetLayeredWindowAttributes的用法)