Android Intents vs. Broadcasts

Intents vs. Broadcasts

–Starting an Activity with an Intent is a foregroundoperation that modifies what the user is currently interacting with.
–Broadcasting an Intent is a backgroundoperation that the user is not normally aware of.

Type of Android Broadcasts

There are two major classes of broadcasts that can be received:
•Normal broadcasts(sent with sendBroadcast) are completely asynchronous. All receivers of the broadcast are run in an undefined order, often at the same time. This is more efficient, but means that receivers cannot use the result or abort APIs included here.
•Ordered broadcasts(sent with sendOrderedBroadcast) are delivered to one receiver at a time. As each receiver executes in turn, it can propagate a result to the next receiver, or it can completely abort the broadcast so that it won't be passed to other receivers. The order receivers run in can be controlled with the android:priorityattribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order.

Broadcast Receiver Life Cycle

A process that is currently executing a BroadcastReceiver(that is, currently running the code in its onReceive(Context, Intent)method) is considered to be a foreground process and will be kept running by the system except under cases of extreme memory pressure.
•Once you return from onReceive(), the BroadcastReceiveris no longer active, and its hosting process is only as important as any other application components that are running in it.
•This means that for longer-running operations you will often use a Servicein conjunction with a BroadcastReceiverto keep the containing process active for the entire time of your operation.

1 comment: