ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 活动中的intent过滤器和广播接收器有什么区别?

2019-08-24 17:26:12  阅读:191  来源: 互联网

标签:android android-intent intentfilter broadcastreceiver


任何人都能告诉我何时应该使用意图过滤器和广播接收器?

<activity>
          <intent-filter></intent-filter>
</activity>

<receiver>
      <intent-filter></intent-filter>
 </receiver>

解决方法:

the documentation开始:

A broadcast receiver is a component that responds to system-wide
broadcast announcements. Many broadcasts originate from the system—for
example, a broadcast announcing that the screen has turned off, the
battery is low, or a picture was captured. Applications can also
initiate broadcasts—for example, to let other applications know that
some data has been downloaded to the device and is available for them
to use. Although broadcast receivers don’t display a user interface,
they may create a status bar notification to alert the user when a
broadcast event occurs. More commonly, though, a broadcast receiver is
just a “gateway” to other components and is intended to do a very
minimal amount of work. For instance, it might initiate a service to
perform some work based on the event.

您可以通过两种方式使用广播接收器.

1)在您的活动中注册和取消注册.当您注册活动时,您需要通过一个小心的操作,当我们从我们的应用程序发送带有该操作的广播时它将会触发.

2)使用广播reciver在清单文件中注册并在清单文件中的intent过滤器中提及操作的第二种方式.

Intent过滤器只不过是简单的说法“它只是我们在日常生活中使用的过滤器”.它将过滤调用它的操作.

Intent过滤器对于活动和广播接收器是相同的.它的主要功能是过滤动作.它取决于我们如何利用它.一个主要的例子是在我们指定的清单文件中的每个应用程序中

<intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

在我们的启动器活动中.它建议这个活动是我们的启动器活动,并将在我们的应用程序开始时首先运行.如果你没有指定它,那么你的应用程序将无法启动.我们也不能在广播接收器的意图过滤器中指定这些类型的过滤器.它们不是应用程序的启动器,

标签:android,android-intent,intentfilter,broadcastreceiver
来源: https://codeday.me/bug/20190824/1710459.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有