A BroadcastReceiver in Android is a component that allows applications to listen for system-wide or app-specific broadcast messages. These messages, or broadcasts, are sent when certain events occur, such as receiving a text message, the device charging, network connectivity changes, or a custom event triggered by an app.
The BroadcastReceiver class enables apps to respond to these events even if the app is not currently running in the foreground. Developers can register receivers either statically in the AndroidManifest.xml or dynamically in code using Context.registerReceiver().
When a broadcast is received, the system calls the onReceive() method of the BroadcastReceiver, where the app can perform short tasks like showing a notification or starting a service. However, it should not perform long-running operations directly inside onReceive() to avoid ANR (Application Not Responding) errors.
There are two main types of broadcasts:
System broadcasts (e.g., BOOT_COMPLETED, BATTERY_LOW)
Custom broadcasts defined by apps for inter-component communication.
From Android 8.0 (API level 26) onward, background limitations were added, restricting implicit broadcasts for better battery life and performance.
Overall, BroadcastReceivers are a powerful tool for building responsive, event-driven Android applications.
Learn more on https://flutterjunction.com/notes/android-application-development