The documentation defines Service as follows:
A Service is an application component that can perform long operations and does not provide a user interface. Another component of the application can start a service and it will continue to run in the background even if the user switches to another application. In addition, a component can bind to a service to interact with it and even establish interprocess communication (IPC). For example, a service can handle network operations, play music, perform file I / O, or interact with a content provider, all from the background.
In turn a BroadcastReceiver is a component that allows you to be registered to receive events.
All registered receivers for an event are notified by Android OS once this event happens.
How long can a Service run (run)?
When started through the startService () the service will remain running until it is stopped on its own with stopSelf () or by the component that started it, calling stopService () .
When started through bindService () it will be running as long as there are linked clients.
A service can be destroyed by the OS when memory is low and needs to recover system resources.
How long can a BroadCastReceiver run (run)?
A BroadcastReceiver is started by the OS if it is eligible for the event being launched.
A BroadcastReceiver is only valid for the duration of the method call OnReceive ()
Once the code returns from this method, the system considers the object complete and no longer active and can be destroyed by the OS.
The documentation says that after 10 seconds the receiver will be blocked and could be destroyed.
Can I create notifications via BroadCastReceiver or just via Service?
If you are referring to the notifications (NotificationManager) that appear in the notification area of the device, yes, it is even a usual way of using BroadcastReceiver.
You can do everything you want in the onReceive () since it is synchronously (1) .
Because this code runs in the main thread do not use them for long processes.
Is it a good practice (the previous question)?
Yes, as I said earlier, posting notifications is a usual way to use BroadcastReceiver.
(1) This limitation can be avoided used registerReceiver (BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) / p>