Search code examples
androidbroadcastreceiverbroadcastandroid-broadcast

Necessity to unregister Broadcast Receiver which is not declared in manifest


Is it necessary to unregister "Broadcast Receiver" when its not mentioned in the manifest file of my Android Studio Project? What are the consequences?


Solution

  • See 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.

    Thus, you needn't to unregister your BroadcaseReceiver if you associate it with an Activity.