Intents and Broadcasts

  1. Explain the concept of an Intent Filter in Android.

    • An Intent Filter is used to specify which intents an activity, service, or broadcast receiver can respond to. It helps filter and match incoming intents.
  2. What is a PendingIntent in Android, and how is it different from a regular Intent?

    • A PendingIntent is a wrapper around an Intent, allowing another application to perform an action on your behalf. It’s often used in situations where an action needs to be deferred or executed by a different app.
  3. What is a BroadcastReceiver in Android, and how is it used?

    • A BroadcastReceiver is a component that responds to system-wide broadcasts or custom events. It’s used to handle asynchronous events and perform tasks in the background.
  4. Explain the difference between an ordered and unordered broadcast in Android.

    • Receivers receive an ordered broadcast in a specific order, with each receiver having the ability to propagate or abort the broadcast. Unordered broadcasts are delivered to all receivers simultaneously.
  5. How can you register a BroadcastReceiver dynamically in your code?

    • You can register a BroadcastReceiver dynamically using the registerReceiver() method in your activity or service and unregister it with unregisterReceiver().
  6. What is an IntentService, and how does it differ from a regular Service?

    • An IntentService is a specialized type of Service designed to perform tasks on a background thread in response to intents. It automatically stops itself when the work is done.