必须注销未在清单中声明的广播接收器
Necessity to unregister Broadcast Receiver which is not declared in manifest
如果我的 Android Studio 项目的清单文件中没有提到 "Broadcast Receiver",是否有必要取消注册?有什么后果?
见this
If used from an Activity context, the receiver is being registered
within that activity. This means that you are expected to unregister
before the activity is done being destroyed; in fact if you do not do
so, the framework will clean up your leaked registration as it removes
the activity and log an error. Thus, if you use the Activity context
to register a receiver that is static (global to the process, not
associated with an Activity instance) then that registration will be
removed on you at whatever point the activity you used is destroyed.
因此,如果您将 BroadcaseReceiver 与 Activity
.
相关联,则无需注销 BroadcaseReceiver
如果您的 BroadcastReceiver
是在 onCreate()
方法中启动的,则必须取消注册,这样当您的 activity 再次启动时,它不会创建另一个,从而导致多个BroadcastReceivers
。
如果我的 Android Studio 项目的清单文件中没有提到 "Broadcast Receiver",是否有必要取消注册?有什么后果?
见this
If used from an Activity context, the receiver is being registered within that activity. This means that you are expected to unregister before the activity is done being destroyed; in fact if you do not do so, the framework will clean up your leaked registration as it removes the activity and log an error. Thus, if you use the Activity context to register a receiver that is static (global to the process, not associated with an Activity instance) then that registration will be removed on you at whatever point the activity you used is destroyed.
因此,如果您将 BroadcaseReceiver 与 Activity
.
如果您的 BroadcastReceiver
是在 onCreate()
方法中启动的,则必须取消注册,这样当您的 activity 再次启动时,它不会创建另一个,从而导致多个BroadcastReceivers
。