是什么活动,广播接收器意图过滤器之间的差异? [英] What is the difference between intent filter in activity and broadcast receiver?

查看:200
本文介绍了是什么活动,广播接收器意图过滤器之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我什么时候应该使用意图过滤器和广播接收器?

 <活性GT;
          &所述;意图滤光器>&下; /意图滤光器>
< /活性GT;

 <接收>
      &所述;意图滤光器>&下; /意图滤光器>
 < /接收器>


解决方案

文档


  

一个广播接收机是响应组件的全系统
  广播公告。许多广播从起源系统为
  例如,一个广播宣布屏幕已关断时,
  电池电量低,或图片被抓获。应用程序也可以
  发起广播 - 例如,让其它应用程序知道
  一些数据被下载到该设备,并为他们提供
  使用。虽然广播接收机不显示用户界面,
  它们可以创建一个状态栏通知来提醒用户时
  发生广播事件。更常见的是,虽然,广播接收机是
  只是网关到其他组件并旨在做得很
  少量的工作。例如,它可能会发起的服务
  执行基于事件的一些工作。


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

1)注册并在activity.When未注册,您与您的活动注册,您需要传递一个行动,它会照顾它会火当我们发送与我们的应用程序的行动播出。

2)使用广播reciver清单文件注册和提意图过滤器行动,在清单文件方式二。

意图过滤器是什么,但在简单的话这只是过滤我们我们平时生活中使用。它会过滤掉调用它的操作。

意图过滤器是相同的活动和广播receiver.Its主要功能是过滤action.It取决于我们如何利用it.One主要的例子就是我们在清单文件中的每个应用程序,我们指定

 <意向滤光器>
        <作用机器人:名字=android.intent.action.MAIN/>
        <类机器人:名字=android.intent.category.LAUNCHER/>
    &所述; /意图滤光器>

在我们的发射activity.It表明这个活动是我们的发射活动,将在开始第一次运行我们的application.If你不指定它,然后你的申请将不launch.Also我们不能在广播接收器的指定这些类型的过滤器意图filter.They不是应用程序启动器,

Can anybody tell me when should I use intent filter and broadcast receiver?

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

and

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

解决方案

From 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.

You can use broadcast receiver by two ways.

1) Registering and un-registering in your activity.When you register with your activity you need to pass an action for which it will take care and it will fire when we send broadcast with that action from our application.

2) Second way to use broadcast reciver to register in manifest file and mention action in intent filter for that in manifest file.

Intent filter is nothing but in simple words "It is filter just we use in our usual lives." It will filter the actions for calling it.

Intent filter is same for activity and broadcast receiver.Its main functioning is to filtering the action.It depends on us how to utilize it.One major example is in our each application in manifest file we specify

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

in our launcher activity.It suggests this activity is our launcher activity and will run first at start of our application.If you not specify it then your application will not launch.Also we can not specify these types of filter in broadcast receiver's intent filter.They are not launcher of apps,

这篇关于是什么活动,广播接收器意图过滤器之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆