We can declare a broadcast receiver in manifest as well as dynamically through code. I want to know the difference in two approaches, and which approach should be used in which case.
Asked
Active
Viewed 53 times
-2
-
Have you read the [SO FAQ](http://stackoverflow.com/faq)? Have you read the [Intent reference](http://developer.android.com/reference/android/content/Intent.html) and searched for `manifest`? – class stacker Mar 08 '13 at 10:18
-
one Which is set via code is active when your process is running via manifest will fire whenever action trigger – DjHacktorReborn Mar 08 '13 at 10:19
-
[BroadCast Receiver efficient initialization][1] [1]: http://stackoverflow.com/questions/4805269/programmatically-register-a-broadcast-receiver That is the right thing., – Tamilselvan Kalimuthu Mar 08 '13 at 10:21
-
Okay I'll also throw in something here. One aspect is the time span during which the receiver can receive messages. However, there's another important aspect, namely that you cannot declare receivers for all broadcasts in the manifest successfully. – class stacker Mar 08 '13 at 10:31
1 Answers
0
I think when you register it via manifest file it is registered forever and you can't unregister it. If it is done programmatically you can register it as well as unregister it.
If you want your broadcast receiver only works when your app is running or if you want to unregister on a certain triggering events then it is good to do programmatic approach.
If you want your broadcast receiver keeps on receiving broadcasts even your app is in sleep or not running and you have no intention of unregistering it then do the manifest registration.

Ariel Magbanua
- 3,083
- 7
- 37
- 48
-
You're right about the _registration_; however, as is pointed out in the A referenced by Tamilselvans comment, there is still a way to _not receive_ intents with a receiver which is _still registered_ via the manifest. – class stacker Mar 08 '13 at 10:33