zoukankan      html  css  js  c++  java
  • intent属性

    private String mAction;
    private Uri mData;
    private String mType;
    private String mPackage;
    private ComponentName mComponent;
    private int mFlags;
    private ArraySet<String> mCategories;
    private Bundle mExtras;
    private Rect mSourceBounds;
    private Intent mSelector;
    private ClipData mClipData;
    private int mContentUserHint = UserHandle.USER_CURRENT;


    http://blog.csdn.net/cnnumen/article/details/8464786

    对于显式Intent,Android不需要去做解析,因为目标组件已经很明确,Android需要解析的是那些隐式Intent,通过解析,将Intent映射给可以处理此Intent的Activity、IntentReceiver或Service。        

       Intent解析机制主要是通过查找已注册在AndroidManifest.xml中的所有IntentFilter及其中定义的Intent,最终找到匹配的Intent。在这个解析过程中,Android是通过Intent的action、type、category这三个属性来进行判断的,判断方法如下:

    Intent属性的设置,包括以下几点:(以下为XML中定义,当然也可以通过Intent类的方法来获取和设置)

    (1)Action,使用android:name特性来指定对响应的动作名。动作名必须是独一无二的字符串,所以,一个好的习惯是使用基于Java包的命名方式的命名系统。SDk中定义了一些标准的动作,包括

    onstant

    Target component

    Action

    ACTION_CALL

    activity

    Initiate a phone call.

    ACTION_EDIT

    activity

    Display data for the user to edit.

    ACTION_MAIN

    activity

    Start up as the initial activity of a task, with no data input and no returned output.

    ACTION_SYNC

    activity

    Synchronize data on a server with data on the mobile device.

    ACTION_BATTERY_LOW

    broadcast receiver

    A warning that the battery is low.

    ACTION_HEADSET_PLUG

    broadcast receiver

    A headset has been plugged into the device, or unplugged from it.

    ACTION_SCREEN_ON

    broadcast receiver

    The screen has been turned on.

    ACTION_TIMEZONE_CHANGED

    broadcast receiver

    The setting for the time zone has changed.

    当然,也可以自定义动作(自定义的动作在使用时,需要加上包名作为前缀,如"com.example.project.SHOW_COLOR”),并可定义相应的Activity来处理我们的自定义动作。

    (2)Data,也就是执行动作要操作的数据

    Android中采用指向数据的一个URI来表示,如在联系人应用中,一个指向某联系人的URI可能为:content://contacts/1。对于不同的动作,其URI数据的类型是不同的(可以设置type属性指定特定类型数据),如ACTION_EDIT指定Data为文件URI,打电话为tel:URI,访问网络为http:URI,而由content provider提供的数据则为content: URIs。

    (3)type(数据类型),显式指定Intent的数据类型(MIME)。一般Intent的数据类型能够根据数据本身进行判定,但是通过设置这个属性,可以强制采用显式指定的类型而不再进行推导。

    (4)category(类别),被执行动作的附加信息。例如 LAUNCHER_CATEGORY 表示Intent 的接受者应该在Launcher中作为顶级应用出现;而ALTERNATIVE_CATEGORY表示当前的Intent是一系列的可选动作中的一个,这些动作可以在同一块数据上执行。还有其他的为

    Constant

    Meaning

    CATEGORY_BROWSABLE

    The target activity can be safely invoked by the browser to display data referenced by a link — for example, an image or an e-mail message.

    CATEGORY_GADGET

    The activity can be embedded inside of another activity that hosts gadgets.

    CATEGORY_HOME

    The activity displays the home screen, the first screen the user sees when the device is turned on or when the HOME key is pressed.

    CATEGORY_LAUNCHER

    The activity can be the initial activity of a task and is listed in the top-level application launcher.

    CATEGORY_PREFERENCE

    The target activity is a preference panel.

    (5)component(组件),指定Intent的的目标组件的类名称。通常 Android会根据Intent 中包含的其它属性的信息,比如action、data/type、category进行查找,最终找到一个与之匹配的目标组件。但是,如果 component这个属性有指定的话,将直接使用它指定的组件,而不再执行上述查找过程。指定了这个属性以后,Intent的其它所有属性都是可选的。

    (6)extras(附加信息),是其它所有附加信息的集合。使用extras可以为组件提供扩展信息,比如,如果要执行“发送电子邮件”这个动作,可以将电子邮件的标题、正文等保存在extras里,传给电子邮件发送组件。

  • 相关阅读:
    JAVA Hibernate工作原理及为什么要用
    Struts2应用流程注解
    查看cpu几核方法
    loadrunner录制获取不到token
    cpu监控
    接口测试
    LoadRunner性能测试结果计数器指标说明
    windows资源监控
    loadrunner检查点
    loadrunner 关联
  • 原文地址:https://www.cnblogs.com/feng9exe/p/5946692.html
Copyright © 2011-2022 走看看