Sobes.tech
Junior — Middle

Can you list different types of Intents depending on their behavior or execution method?

sobes.tech AI

Answer from AI

In Android, Intents can be classified by several criteria:

  1. By execution method:

    • Explicit Intent — specifies a particular component (Activity, Service, or BroadcastReceiver) to start. Used when the exact component name is known.
    • Implicit Intent — does not specify a particular component but describes an action to perform. The system selects an appropriate component that can handle this Intent.
  2. By action type:

    • Activity Intent — for starting an Activity.
    • Service Intent — for starting or interacting with a Service.
    • Broadcast Intent — for sending broadcast messages.
  3. By transmission method:

    • Sticky Intent — an Intent that is retained by the system after sending so that new receivers can get the last Intent.

Example of an explicit Intent to start an Activity:

Intent intent = new Intent(this, TargetActivity.class);
startActivity(intent);

Example of an implicit Intent to open a web page:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com"));
startActivity(intent);