Android – Intents

An intent is a message one component send to another component to interact with or request some functionality from. Intents have data fields and some can be passed from one component to another like passing arguments to a method. One of those fields is the name of the component that will handle the intent. If you specify the name then this intent is called explicit intent. If the name is omitted, then you need to specify other fields, action, data and/or category. This intent is called implicit intent and is handled by the intent resolution which maps it to an Activity, BroadcastReceiver or Service. (it is not recommended to start a service with implicit intent).

Android studio and intents., <span>Android – Intents</span>, KandZ

Methods to use intents you created:

  • startActivity() – Launches an activity with the intent you created
  • startActivityWithResult() – the same as above but also it receives information back
  • sendBroadcast() – send event intents to Broadcast Receivers
  • startService() / bindService() – launches and communicates with a single service.

Intent attributes

  • name/component – identifies the component that can receive an intent. Components usually resides in the same app
Intent intent = new Intent(context, CompononentNme.class);
  • action – describes an operation to perform(activity) or an event that has occurred(broadcast Receiver). Data and extras are needed. Full list of activity actions and full list of events/Broadcast actions.
  • data – defines the data an intent should operate on such as a Uri
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:+30"+telNumber));
  • extras – provides additional information delivered with intent. Stored as a Bundle that is a key-value pair. Can be sent from app to app and process to process. Here is also a full list of Extra Data that can be used as extra data via putExtra().
Intent intent = new Intent(context, ActivityToOpen.class);
  • category – provides Android OS with the type of component that can handle an intent. Full list of standard categories.
Intent intent = new Intent(Intent.ACTION_VIEW,uri)
  • flags – specifies how Android itself handles an intent. Here is the full list.
Intent intent = new Intent(Intent.ACTION_SEND)

You can read more here.


91330cookie-checkAndroid – IntentsAndroid – Intents

Related posts

One Thought to “Android – Intents

Comments are closed.