Intents and Intent Filters---Intent Objects

[b]Intent Objects[/b]

An Intent object is a bundle of information. It contains information of interest to the component that receives the intent (such as the action to be taken and the data to act on) plus information of interest to the Android system (such as the category of component that should handle the intent and instructions on how to launch a target activity). Principally, it can contain the following:

翻译:intent对象是一个包含请求信息的对象,包含可能被激活的目标组件所关心的信息比如action、目标组件可能要操作的数据以及目标组件运行环境(Android系统)所关心的信息(如目标组件的类别描述信息和如何发射一个目标组件即activity的指令性信息)。一个intent对象中主要包含以下信息:

[b]一、Component name[/b]
The name of the component that should handle the intent. This field is a ComponentName object — a combination of the fully qualified class name of the target component (for example "com.example.project.app.FreneticActivity") and the package name set in the manifest file of the application where the component resides (for example, "com.example.project"). The package part of the component name and the package name set in the manifest do not necessarily have to match.

The component name is optional. If it is set, the Intent object is delivered to an instance of the designated class. If it is not set, Android uses other information in the Intent object to locate a suitable target — see Intent Resolution, later in this document.

翻译:该属性是响应intent的组件的名称,是ComponentName对象,用来设定响应intent对象的目标组件的完整类名,例如:"com.example.project.app.FreneticActivity",准确说该属性将包含两种信息:类名+包名,在Android应用的manifest文件中包名信息与这个属性中的包名信息不是说必须要匹配的。需要说明的是该属性不是必须指定的属性,如果被指定的话,该intent对象将送交给指定名称的组件的一个实例,如果没有指定,Android系统将根据当前 intent对象中的其他信息来判定哪个组件是最为适合的目标组件,组件名信息的设置和取得可以通过以下方法执行。

The component name is set by setComponent(), setClass(), or setClassName() and read by getComponent().

[b]二、Action[/b]
A string naming the action to be performed — or, in the case of broadcast intents, the action that took place and is being reported. The Intent class defines a number of action constants, including these:【翻译:这个属性是一个字符串属性,用来描述要求目标组件实例执行的操作,Intent 类中预定义了若干action常量,例如:】


[img]http://dl.iteye.com/upload/attachment/302257/427e714c-22d1-3369-9a62-95e6608a3cd0.png[/img]

See the Intent class description for a list of pre-defined constants for generic actions. Other actions are defined elsewhere in the Android API. You can also define your own action strings for activating the components in your application. Those you invent should include the application package as a prefix — for example: "com.example.project.SHOW_COLOR". 【翻译:Intent的类描述文档中预定义了很多可以直接使用的action常量,在Android API的其他地方也有预定义的action常量,开发者也可以自定义action常量(把你的 应用的包名作为自定义action常量的前缀),例如:"com.example.project.SHOW_COLOR"。】

The action largely determines how the rest of the intent is structured — particularly the data and extras fields — much as a method name determines a set of arguments and a return value. For this reason, it's a good idea to use action names that are as specific as possible, and to couple them tightly to the other fields of the intent. In other words, instead of defining an action in isolation, define an entire protocol for the Intent objects your components can handle.

The action in an Intent object is set by the setAction() method and read by getAction().

【翻译:[b]action属性[/b]会很大程度决定intent对象的其他信息的构成,尤其是[b]data属性[/b]和[b]extras属性[/b],这就如同方法名决定了方法的参数以及是否有返回值是一个道理,该属性的设定和读取可以用setAction() 和 getAction()方法执行。】

[b]三、Data[/b]
The URI of the data to be acted on and the MIME type of that data. Different actions are paired with different kinds of data specifications. For example, if the action field is ACTION_EDIT, the data field would contain the URI of the document to be displayed for editing. If the action is ACTION_CALL, the data field would be a tel: URI with the number to call. Similarly, if the action is ACTION_VIEW and the data field is an http: URI, the receiving activity would be called upon to download and display whatever data the URI refers to.

【翻译:[b]data属性[/b]由两部分内容构成:[b]数据URI[/b]和[b]数据的MIME类型[/b],不同的[b]action属性[/b]往往决定了[b]data属性[/b]。比如,如果说action属性被设定为ACTION_EDIT,那么data属性就可能是:将要显示并允许用户编辑的数据的URI;如果action属性被设定为ACTION_CALL,那么data属性就应该是tel: URI和要呼叫的电话号码;如果action属性被设定为ACTION_VIEW,data属性的URI是http:,那么目标activity将根据URI指定的地址,下载并显示相关数据。】

When matching an intent to a component that is capable of handling the data, it's often important to know the type of data (its MIME type) in addition to its URI. For example, a component able to display image data should not be called upon to play an audio file.

【翻译:当系统根据intent对象找到与之相匹配的组件来处理数据的时候,系统除了需要知道数据的URI(数据存储的URI)以外,还必须知道要的数据类型,也就是URI所关联的[b]数据的MIME类型[/b]。】

In many cases, the data type can be inferred from the URI — particularly content: URIs, which indicate that the data is located on the device and controlled by a content provider (see the separate discussion on content providers). But the type can also be explicitly set in the Intent object. The setData() method specifies data only as a URI, setType() specifies it only as a MIME type, and setDataAndType() specifies it as both a URI and a MIME type. The URI is read by getData() and the type by getType().

【翻译:多数情况下数据类型可以从URI中推导出来,尤其是URI=content:的时候,这时候数据通常是位于本设备上而且是由某个content provider来控制的。即使如此,还是可以在intent对象中明确设定[b]数据的MIME类型[/b],setData() 方法设定数据的MIME类型,setType() 方法设定 MIME type, setDataAndType()方法可以同时设定这两个属性。】

[b]四、Category[/b]
A string containing additional information about the kind of component that should handle the intent. Any number of category descriptions can be placed in an Intent object. As it does for actions, the Intent class defines several category constants, including these: 翻译:[b]种类属性[/b]用来设定目标组件的类别信息,起着对[b]action属性[/b]的补充说明作用。一个intent中可以设定多个种类信息,和action属性一样,系统也在intent类中预定义了几个种类常量:

[img]http://dl.iteye.com/upload/attachment/302259/a2d24a46-976f-3f27-a0a5-cbdca53b8da7.png[/img]

See the Intent class description for the full list of categories.

The addCategory() method places a category in an Intent object, removeCategory() deletes a category previously added, and getCategories() gets the set of all categories currently in the object. 【翻译:使用addCategory() 方法可以添加一个种类属性信息,使用removeCategory() 方法可以删除一个种类属性信息;可以用getCategories()方法取得当前intent实例中所有种类属性信息。】

[b]五、Extras[/b]
Key-value pairs for additional information that should be delivered to the component handling the intent. Just as some actions are paired with particular kinds of data URIs, some are paired with particular extras. For example, an ACTION_TIMEZONE_CHANGED intent has a "time-zone" extra that identifies the new time zone, and ACTION_HEADSET_PLUG has a "state" extra indicating whether the headset is now plugged in or unplugged, as well as a "name" extra for the type of headset. If you were to invent a SHOW_COLOR action, the color value would be set in an extra key-value pair. 【翻译:[b]Extras信息[/b]是Key-value形式的附加信息,存放在intent中用来传递给某个组件,可以理解为方法调用时的参数。】

The Intent object has a series of put...() methods for inserting various types of extra data and a similar set of get...() methods for reading the data. These methods parallel those for Bundle objects. In fact, the extras can be installed and read as a Bundle using the putExtras() and getExtras() methods.

【翻译:Intent对象有一套方法名如同put...()的方法,可以用来向intent对象插入各种类型的Extras信息。同样也有着方法名如同get...()的方法可以取得各种类型的Extras信息。使用putExtras() 和 getExtras()方法同样可以设定或读取Extras信息,这时候两个方法的参数(putExtras())或返回值(getExtras())是Bundle实例。】

[b]六、Flags[/b]
Flags of various sorts. Many instruct the Android system how to launch an activity (for example, which task the activity should belong to) and how to treat it after it's launched (for example, whether it belongs in the list of recent activities). All these flags are defined in the Intent class. 【翻译:[b]Flags属性[/b]的种类比较多。多数Flags属性是为了告知Android系统如何发射某个目标activity组件的,比如目标activity组件实例是属于当前task还是新建的一个task;如果当前栈顶恰好是该目标组件实例的话,系统如何处理。】

The Android system and the applications that come with the platform employ Intent objects both to send out system-originated broadcasts and to activate system-defined components. To see how to structure an intent to activate a system component, consult the list of intents in the reference.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的公寓报修管理系统,源码+数据库+毕业论文+视频演示 现代经济快节奏发展以及不断完善升级的信息化技术,让传统数据信息的管理升级为软件存储,归纳,集中处理数据信息的管理方式。本公寓报修管理系统就是在这样的大环境下诞生,其可以帮助管理者在短时间内处理完毕庞大的数据信息,使用这种软件工具可以帮助管理人员提高事务处理效率,达到事半功倍的效果。此公寓报修管理系统利用当下成熟完善的Spring Boot框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的MySQL数据库进行程序开发。公寓报修管理系统有管理员,住户,维修人员。管理员可以管理住户信息和维修人员信息,可以审核维修人员的请假信息,住户可以申请维修,可以对维修结果评价,维修人员负责住户提交的维修信息,也可以请假。公寓报修管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 关键词:公寓报修管理系统;Spring Boot框架;MySQL;自动化;VUE
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值