当前位置:  编程技术>移动开发
本页文章导读:
    ▪Intents and Intent Filters-Intent Objects        Intents and Intent Filters---Intent Objects Intent Objects   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 info.........
    ▪ 他们实在太。猖獗了        他们实在太。疯狂了 他们实在太。疯狂了 ......
    ▪ 常用语媾和地区代码       常用语言和地区代码 da_DK  丹麦语  丹麦  DE_AT  德语  奥地利  DE_CH  德语  瑞士  DE_DE  德语  德国  el_GR  希腊语  希腊  en_CA  英语  加拿大  en_GB  英语  联合王国  en.........

[1]Intents and Intent Filters-Intent Objects
    来源: 互联网  发布时间: 2014-02-18
Intents and Intent Filters---Intent Objects
Intent Objects

   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对象中主要包含以下信息:

一、Component name
    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().

二、Action
    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常量,例如:】




    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().

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

三、Data
    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.

    【翻译:data属性由两部分内容构成:数据URI和数据的MIME类型,不同的action属性往往决定了data属性。比如,如果说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所关联的数据的MIME类型。】

    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对象中明确设定数据的MIME类型,setData() 方法设定数据的MIME类型,setType() 方法设定 MIME type, setDataAndType()方法可以同时设定这两个属性。】

四、Category
    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: 翻译:种类属性用来设定目标组件的类别信息,起着对action属性的补充说明作用。一个intent中可以设定多个种类信息,和action属性一样,系统也在intent类中预定义了几个种类常量:



   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实例中所有种类属性信息。】

五、Extras
    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. 【翻译:Extras信息是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实例。】

六、Flags
    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. 【翻译:Flags属性的种类比较多。多数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.

    
[2] 他们实在太。猖獗了
    来源: 互联网  发布时间: 2014-02-18
他们实在太。疯狂了
他们实在太。疯狂了

    
[3] 常用语媾和地区代码
    来源: 互联网  发布时间: 2014-02-18
常用语言和地区代码

da_DK  丹麦语  丹麦  
DE_AT  德语  奥地利  
DE_CH  德语  瑞士  
DE_DE  德语  德国  
el_GR  希腊语  希腊  
en_CA  英语  加拿大  
en_GB  英语  联合王国  
en_IE  英语  爱尔兰  
en_US  英语  美国  
es_ES  西班牙语  西班牙  
fi_FI  芬兰语  芬兰  
fr_BE  法语  比利时  
fr_CA  法语  加拿大  
fr_CH  法语  瑞士  
fr_FR  法语  法国  
it_CH  意大利语  瑞士  
it_IT  意大利语  意大利  
ja_JP  日语  日本  
ko_KR  韩国语  韩国  
nl_BE  荷兰语  比利时  
nl_NL  荷兰语  荷兰  
no_NO  挪威语 (Nynorsk)  挪威  
no_NO_B  挪威语 (Bokm?l)  挪威  
pt_PT  葡萄牙语  葡萄牙  
sv_SE  瑞典语  瑞典  
tr_TR  土耳其语  土耳其  
zh_CN  中文(简体)  中国  
zh_TW  中文(繁体)  中国台湾


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3