im trying to understand what the difference between a service and a broadcast receiver is, as i see it they can do the same thing.
For example i have an application : App1 that provide a service called ToastHelloWorld which just creates a Toast and stopSelf(). I expose it to other applications using an intent filter with the action name: "com.test.HelloToast"
Now i have another application : App2 i want to implicit use a service with the action "com.test.HelloToast" so i call startService(new Intent("com.test.HelloToast"));
and it works.
Why would i use broadcast receivers when i can do everything with services and dont have the restriction of a 5sec execution limit?.
I know most "system events" is exposed via broadcasts' but couldnt they just aswell be published as Service Intents ?
Broadcast intents are usually delivered to all BroadcastReceivers registered for that intent. (There is an exception with ordered intents where a receiver can abort the delivery for lower priority receivers) Intents that start or bind services are only sent to one matching Service instance.
Some broadcast intents are sticky. That means they might have been sent in the past and will be delivered when your app registers the receiver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With