Intent
What is Intent:
An Android Intent can be used to perform following 3 tasks :
Let us see an example:
- An intent is an abstract description of an operation to be performed.
- It
can be used with
startActivity
to launch anActivity
,broadcastIntent
to send it to any interestedBroadcastReceiver
components, andstartService(Intent)
orbindService(Intent, ServiceConnection, int)
to communicate with a backgroundService
.
- Open another Activity or Service from the current Activity
- Pass data between Activities and Services
- 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:
- Explicit Intent
- 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);
0 comments:
Post a Comment