Wednesday 14 October 2015

Types Of Intents

Intent

What is Intent:

  • An intent is an abstract description of an operation to be performed. 

An Android Intent can be used to perform following 3 tasks :
  1. Open another Activity or Service from the current Activity
  2. Pass data between Activities and Services
  3. Delegate responsibility to another application. For example, you can use Intents to open the browser application to display a URL.


We Have Two Types Intent:

  1. Explicit Intent
  2. Implicit Intent

Explicit Android Intent:

  • Explicit Android Intent is the Intent in which you explicitly define the component that needs to be called by Android System.

  • When you open an activity from another activity in the same Android app, you use Explicit Intents. Let us understand through an example :

    Intent CodeLearnFirstIntent = new Intent (getApplicationContext(), SecondActivity.class);
  •   you are passing the SecondActivity class name as an identifier for this intent.

Let's see an example:

 

Implicit Android Intent:

  • Implicit Android Intents is the intent where instead of defining the exact components, you define the action you want to perform. 

  • The decision to handle this action is left to the operating system. 

  • The OS decides which component is best to run for implicit intents.

  • Whenever you delegate responsibility to another application from your application, you use Implicit Intents.

Let us see an example:

                Intent sendIntent = new Intent();

                         sendIntent.setAction(Intent.ACTION_SEND); 




Let us now observe a couple of examples to see how Intent works, how you pass data and how you use Implicit Intents to delegate responsibilities to other apps.

 

 

0 comments:

Post a Comment