Android知识总结(问答形式)一

来源:互联网 发布:射雕英雄传电视剧 知乎 编辑:程序博客网 时间:2024/06/05 06:45

  • Activity和receiver的区别
  • category default必须定义
  • exported browsable intentfilter

Activity和receiver的区别

总感觉有点类似,但是:
Note: For all activities, you must declare your intent filters in the manifest file. However, filters for broadcast receivers can be registered dynamically by calling registerReceiver(). You can then unregister the receiver with unregisterReceiver(). Doing so allows your app to listen for specific broadcasts during only a specified period of time while your app is running.

在receiver中可以启动activity,但是不推荐。

broadcast出来的intent可以针对好多接受者,是个事件通知功能。
用intent 启动activity只能启动一个

category default必须定义?

To advertise which implicit intents your app can receive, declare one or more intent filters for each of your app components with an <intent-filter> element in your manifest file.

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.
那,我不定义category default的话,explicit intent不需要intent filter,而implicit intent调用的话,又调用不到。岂不是没定义category default的intent filter没用?
但是,发现打开app的第一个activity的category中没有default category,只有launcher。

The CATEGORY_LAUNCHER category indicates that this activity’s icon should be placed in the system’s app launcher. If the element does not specify an icon with icon, then the system uses the icon from the element.

所以,这就理解了,主要是系统启动应用并不是用startActivity,所以没事。

exported? browsable? intentfilter?

exported:
如果不是exported的,用root可以调用起来。
如果没有指定exported,那么有intent filter则是exported,没有就不是。
就算不是exported,也可能通过一个exported的broadcast receiver调起来,但可能性不大?

browsable:
如果定义

    <intent-filter>      ...      <data android:scheme="https" android:host="www.example.com" />      <data android:scheme="app" android:host="open.my.app" />    </intent-filter>

那么It might seem as though this supports only https://www.example.com and app://open.my.app.
However, it actually supports those two, plus these: app://www.example.com and https://open.my.app.
所以,得分成两个intent filter写。

原创粉丝点击