阅读笔记2
来源:互联网 发布:放逐之城4.5数据 编辑:程序博客网 时间:2024/05/18 10:08
1。Note: In order to receive implicit intents, you must include the CATEGORY_DEFAULT
category in the intent filter. The methods startActivity()
and startActivityForResult()
treat all intents as if they declared the CATEGORY_DEFAULT
category. If you do not declare this category in your intent filter, no implicit intents will resolve to your activity.
注意:为了能接收到隐式意图,你必须在intent filter里包含category 为CATEGORY_DEFAULT。startActivity和startActivityForResult将所有的intents看成他们所声明的CATEGORY_DEFAULT category。如果你不声明该属性,没有隐式意图将会解析你的activity
2.Caution: To avoid inadvertently running a different app'sService
, always use an explicit intent to start your own service and do not declare intent filters for your service. 为了避免无意中打开不同APP的Service,确保用显示意图来开启自己的service,并且在service中不要声明intent filters
3.Major use cases for a pending intent include:
- Declare an intent to be executed when the user performs an action with your Notification (the Android system's
NotificationManager
executes theIntent
). - Declare an intent to be executed when the user performs an action with your App Widget (the Home screen app executes the
Intent
). - Declare an intent to be executed at a specified time in the future (the Android system's
AlarmManager
executes theIntent
). - pendingintent 主要的使用情况宝包括以下:
- 1。当用户点击了你的通知的时候,声明一个即将要执行的intent。安卓系统的NotificationManager执行intent。
- 2.当用户操作你的应有程序的窗口小组件的时候,声明一个即将要执行的intent。主屏幕的app执行intent。
- 3.声明一个在未来某个指定的时间执行的intent。比如闹钟
4. You must instead declare the intended component type when you create thePendingIntent
by calling the respective creator method:
PendingIntent.getActivity()
for anIntent
that starts anActivity
.PendingIntent.getService()
for anIntent
that starts aService
.PendingIntent.getBroadcast()
for aIntent
that starts anBroadcastReceiver
.- Unless your app is receiving pending intents from other apps, the above methods to create a
PendingIntent
are the onlyPendingIntent
methods you'll probably ever need. - 你必须用个自己的创建方法来代替声明的intent,除非你的app接收到了来自其他app的pending intents,否则上述的方法你将不需要
- The intent action
- The intent data (both URI and data type)
- The intent category
The following sections describe how intents are matched to the appropriate component(s) in terms of how the intent filter is declared in an app's manifest file.
当你的系统受到隐式意图来打开一个activity时,系统将会通过比较intent filters的三个方面来选出最适合的activity。intent action,intent data,intent category。intents怎么来匹配最合适的组件是根据app 的manifest file中intent的定义来实现的。
To get through this filter, the action specified in the Intent
must match one of the actions listed in the filter.
If the filter does not list any actions, there is nothing for an intent to match, so all intents fail the test. However, if an Intent
does not specify an action, it will pass the test (as long as the filter contains at least one action).
For an intent to pass the category test, every category in the Intent
must match a category in the filter. The reverse is not necessary—the intent filter may declare more categories than are specified in the Intent
and theIntent
will still pass. Therefore, an intent with no categories should always pass this test, regardless of what categories are declared in the filter.
categories ,如果一个intent设置了一个或者多个category,必须全部与intent filter里德category匹配才能通过匹配。intent filter的category可以多于intent里设置的,但是intent里设置了的就必须要有匹配。intent没有设置,通过匹配,不管filter里怎么声明的。
Note: Android automatically applies the the CATEGORY_DEFAULT
category to all implicit intents passed tostartActivity()
and startActivityForResult()
. So if you want your activity to receive implicit intents, it must include a category for "android.intent.category.DEFAULT"
in its intent filters (as shown in the previous <intent-filter>
example.
所有的隐式意图在调用startActivity或者forReslut时,会默认加上category为default。如果你想你的activity来匹配该隐式意图,你必须在你的intent filter声明中加入default的category声明。
6.Each <data>
element can specify a URI structure and a data type (MIME media type). There are separate attributes — scheme
, host
, port
, and path
— for each part of the URI:
<scheme>://<host>:<port>/<path>
For example:
content://com.example.project:200/folder/subfolder/etc
Each of these attributes is optional in a <data>
element, but there are linear dependencies:
- If a scheme is not specified, the host is ignored.
- If a host is not specified, the port is ignored.
- If both the scheme and host are not specified, the path is ignored.
When the URI in an intent is compared to a URI specification in a filter, it's compared only to the parts of the URI included in the filter. For example:
- If a filter specifies only a scheme, all URIs with that scheme match the filter.
- If a filter specifies a scheme and an authority but no path, all URIs with the same scheme and authority pass the filter, regardless of their paths.
- If a filter specifies a scheme, an authority, and a path, only URIs with the same scheme, authority, and path pass the filter.
如果制定了scheme和acthority,但是并没有指定path,只要两者匹配即可。
如果都指定了,全部匹配才行
The rules are as follows:
- An intent that contains neither a URI nor a MIME type passes the test only if the filter does not specify any URIs or MIME types.
- An intent that contains a URI but no MIME type (neither explicit nor inferable from the URI) passes the test only if its URI matches the filter's URI format and the filter likewise does not specify a MIME type.
- An intent that contains a MIME type but not a URI passes the test only if the filter lists the same MIME type and does not specify a URI format.
- An intent that contains both a URI and a MIME type (either explicit or inferable from the URI) passes the MIME type part of the test only if that type matches a type listed in the filter. It passes the URI part of the test either if its URI matches a URI in the filter or if it has a
content:
orfile:
URI and the filter does not specify a URI. In other words, a component is presumed to supportcontent:
andfile:
data if its filter lists only a MIME type.
PackageManager
has a set of query...()
methods that return all components that can accept a particular intent, and a similar series of resolve...()
methods that determine the best component to respond to an intent. For example,queryIntentActivities()
returns a list of all activities that can perform the intent passed as an argument, and queryIntentServices()
returns a similar list of services. Neither method activates the components; they just list the ones that can respond. There's a similar method, queryBroadcastReceivers()
, for broadcast receivers.intent并没有指定URI和MIME type,通过的唯一可能是filter也没指定任何URI和MIMEintent制定了URI没有指定MIME,通过的唯一情况是URI匹配,并且filter并没有指定MIME
intent 指定了MIME没有指定URI,通过的唯一情况是MIME类型匹配,并且fileter没有指定URI
intent指定了URI和MIME,通过MIME type部分必须匹配filter列出的MIME的类型。它通过URI的部分要么filter的UR与intent的URI相匹配,要么intent含有content:或者file:而filter并没有指定URI。换句话说,一个组件假定支持contnet:和file:data类型,当filter仅仅列出mime type的时候。
queryIntentActivities()
returns a list of all activities that can perform the intent passed as an argument, and queryIntentServices()
returns a similar list of services. Neither method activates the components; they just list the ones that can respond. There's a similar method, queryBroadcastReceivers()
, for broadcast receivers.
三个方法~
- 《影响力2》阅读笔记
- mudos阅读笔记2
- TCPL 阅读笔记 2
- 论文阅读笔记2
- 阅读笔记(2)
- 阅读笔记2
- Veloview阅读笔记2
- 论文阅读笔记2
- x264源码阅读笔记2
- DA9034驱动程序阅读笔记(2)
- x264代码阅读笔记2
- X264代码阅读笔记2
- effective C++ 阅读笔记 2
- ActiveAndroid 源码阅读笔记 (2)
- flashsim源码阅读笔记2
- 操作系统概念阅读笔记2
- django 1.8.2 阅读笔记
- fg代码阅读笔记2
- Scala学习笔记(一) 基础类型
- MyBatis批量增删改
- T60/T60p显卡的官方Windows 7驱动下载网址
- 拓扑排序
- STL容器list
- 阅读笔记2
- Android瀑布流StaggeredGridView学习研究
- IT女娃开博啦。。
- SQL中Null需要注意的地方
- 逐行读txt文件(读写文件try catch finally 处理空行,编码格式,文件流释放问题,处理读到重复问题)
- HDOJ-5446/2015 ACM/ICPC Asia Regional Changchun Online 1010(数论)
- UML——活动图
- 关于handler的注解 @SuppressLint("HandlerLeak") 的理解和dialogshow不出来
- Hadoop 去重排序加序号