Sobes.tech
Junior — Middle

Can you name the types of messages that the BroadcastReceiver component in Android can handle?

sobes.tech AI

Answer from AI

The BroadcastReceiver component in Android can handle various types of messages (broadcasts), which are divided into two main categories:

  1. System-wide broadcast messages — sent by the Android system itself to notify applications about events, such as:

    • Network connectivity change (CONNECTIVITY_CHANGE)
    • Device charging (ACTION_POWER_CONNECTED)
    • Device boot completion (BOOT_COMPLETED)
  2. User (local) broadcast messages — created and sent by applications to exchange information within or between applications.

Example of handling a system message in BroadcastReceiver:

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            // Actions after device boot
        }
    }
}

Thus, BroadcastReceiver allows reacting to various system and application events.