Intent小结

Intent是个android中nb的东西,可以说整个系统都是由他来给串联起来的,四个丸子中的三个,Activity,Service和BroadcastReceiver都是通过Intent机制激活的,所以有称Intent是一种运行时绑定(run-time binding)机制,它能在程序运行的过程中连接两个不同的组件。Intent一旦发出,包括startActivity(), startActivityForResult(),startService(), bindService(),sendBroadcast(),和sendOrderBroadcast(),sendStickBroadcast()等,android都会准确的找到相匹配的一个或者多个Activity,Service或者BroadcastReceiver作为响应,这三类不会被混在一起的,一个Intent不可能既关联Activity也关联Receiver。

 

Intent的主要组成部分

Intent对象抽象地描述了要执行的操作,其描述的基本内容可以分为组件名称(显示),Action,Data,Category,Extra和Flag 6部分。

(1)组件名称是指Intnet目标组件的名称。组件名称是一个ComponentName对象,这种对象名称是目标组件的类名和目标组件所在应用程序的包名的组合。组件中包名不一定要和manifest文件中的包名完全匹配。这是个可选项,但是一旦指定了组件名称,这就是个显示消息,Intent会传递给指明的组件。

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

(2)Action描述Intent所触发动作名称的字符串,下面是系统中比较常用的action

Activity的Action

ACTION_CALL 拨出Data里指定的电话号码

ACTION_EDIT 打开编辑Data里指定数据相应的应用程序

ACTION_MAIN 主程序的入口,不会接受数据,结束后不会返回数据,和Action_View最常用

ACTION_SYNC 在Android平台和服务器之间同步数据

ACTION_VIEW 根据Data类型的不同,打开相对应的应用程序以显示数据

ACTION_DIAL 启动Dialer或其他拨号程序,并显示Data里指定的电话号码

ACTION_SENDTO 向Data里描述的目标地址发送数据

其他的

ACTION_ATTACH_DATA Used to indicate that some piece of data should be attached to some other place. For example, image data could be attached to a contact. It is up to the recipient to decide where the data should be attached; the intent does not specify the ultimate destination.

 

ACTION_PICK Activity Action: Pick an item from the data, returning what was selected.

Input: getData() is URI containing a directory of data (vnd.android.cursor.dir/*) from which to pick an item.

Output: The URI of the item that was picked.

 

ACTION_CHOOSER Activity Action: Display an activity chooser, allowing the user to pick what they want to before proceeding. This can be used as an alternative to the standard activity picker that is displayed by the system when you try to start an activity with multiple possible matches, with these differences in behavior:

Output: Depends on the protocol of EXTRA_INTENT.

  • You can specify the title that will appear in the activity chooser.
  • The user does not have the option to make one of the matching activities a preferred activity, and all possible activities will always be shown even if one of them is currently marked as the preferred activity.

This action should be used when the user will naturally expect to select an activity in order to proceed. An example if when not to use it is when the user clicks on a "mailto:" link. They would naturally expect to go directly to their mail app, so startActivity() should be called directly: it will either launch the current preferred app, or put up a dialog allowing the user to pick an app to use and optionally marking that as preferred.

In contrast, if the user is selecting a menu item to send a picture they are viewing to someone else, there are many different things they may want to do at this point: send it through e-mail, upload it to a web service, etc. In this case the CHOOSER action should be used, to always present to the user a list of the things they can do, with a nice title given by the caller such as "Send this photo with:".

As a convenience, an Intent of this form can be created with the createChooser(Intent, CharSequence) function.

Input: No data should be specified. get*Extra must have a EXTRA_INTENT field containing the Intent being executed, and can optionally have a EXTRA_TITLE field containing the title text to display in the chooser.

 

ACTION_CET_CONTENT

ACTION_SEND

ACTION_ANSWER

ACTION_INSERT

ACTION_DELETE

ACTION_RUN

ACTION_PICK_ACTIVITY

ACTION_SEARCH

ACTION_WEB_SEARCH

ACTION_FACTORY_TEST

 

标准的broadcastReceiver的Action

ACTION_TIME_TICK 系统时间每过一分钟分成的广播

ACTION_TIME_CHANGED 系统时间通过设置发生了改变

ACTION_TIMEZONE_CHANGED 时区改变

ACTION_BOOT_COMPLETED 系统启动完毕

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值