的BroadcastReceiver的清单和计划登记的主要区别

编程入门 行业动态 更新时间:2024-10-11 01:20:54
本文介绍了的BroadcastReceiver的清单和计划登记的主要区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想了解注册一个BroadcastReceiver在清单中,并以编程方式对其进行注册的...

I am trying to understand the main differences between registering a BroadcastReceiver in the Manifest and registering it programmatically...

我的理解是基本如下 - 将AP preciate有人纠正我的观点,如果我失去了一些东西。

My understanding is basically as follows - would appreciate someone correcting my points if I am missing something.

在注册清单: - 操作系统会奇迹般地发现,如果需要实例化类,调用的onReceive()方法,无论你的应用程序的运行状态是 - 您收到只会被调用一次,每次广播(即你可以考虑注册在清单就像你注册类用于接收广播 - 与广播实例化类需要)(??)

Registered in Manifest: - The OS will magically find and instantiate your class if needed, calling the onReceive() method, regardless what the running state of your application was - Your receive will only get called once per broadcast (i.e. You can consider that registering in the manifest is like registering your 'class' for receiving the broadcast - and the broadcast instantiates your class as needed) (??)

注册编程方式: - 登记在code意味着你要注册你的类的实例来接收广播信息(例如,如果你的code是一个有点草率,你设法注册了几次,你最终会与多个BroadcastReceiver的实例的所有有他们的onReceive()呼吁广播 - 取消注册,则需要注销您$ pviously注册p $特定的BroadcastReceiver实例 - 如果你的应用程序时由操作系统被破坏,你的onReceive()方法将不会被要求广播

Registered Programmatically: - registering in code means that you are registering instances of your class to receive broadcast messages (i.e. if your code is a little sloppy, and you manage to register several times, you will end up with multiple BroadcastReceiver instances all having their onReceive() called for a broadcast - to deregister, you need to deregister the specific BroadcastReceiver instance that you previously registered - if your application gets destroyed by the OS, your onReceive() method will not be called for a broadcast

感谢

推荐答案

您有它基本上是正确的。

You have it basically correct.

请注意,一个明显的注册的接收器对象仅使用一次。你的的BroadcastReceiver 为每个广播创造了一个新的实例。主要用途清单注册的接收器是广播,可能会去,而你的code不是在内存中(例如, BOOT_COMPLETED ,通过 AlarmManager )。

Note that a manifest-registered receiver object is only used once. A new instance of your BroadcastReceiver is created for each broadcast. The primary use of manifest-registered receivers is for broadcasts that may go on while your code is not in memory (e.g., BOOT_COMPLETED, your scheduled alarms via AlarmManager).

更多推荐

的BroadcastReceiver的清单和计划登记的主要区别

本文发布于:2023-11-27 10:59:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637791.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:清单   区别   计划   BroadcastReceiver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!