Thursday 25 January 2018

What is intent ? and types of intents.

Intent:

Definition of Intents:
ØAn  Intent is a data structure that specifies
üAn operation to be performed 
üAn event that has occurred
ØBroadcast by one component 
ØReceived by 0 or more components 
ØTo start an activity
ØTo start a service
ØAn intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.
ØAn Intent provides a facility for performing late runtime binding between the code in different applications. 

Types of Intents:

ØExplicit Intents: have specified a component which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application.

Example:

ØIntent myIntent   =    new Intent(ThisActivity.this, ThatActivity.class);           
Ø startActivity(myIntent );

ØImplicit Intents: have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.

Intent for Activities:
ØIntents can be used to activate Activities
üstartActivity(Intent intent)
üstartActivityForResult(Intent intent, …) 
ØThe target Activity can be  
üNamed explicitly in the Intent, or  
Determined implicitly via intent resolution

Intent Resolution: 

ØA process for matching Intents with Activities  that want to receive them 
ØIntent Filters describe which Intents an  Activity can handle 
üUsually specified in an AndroidManifest.xml file 
ØIntent Resolution only matches 
üAction
üData (both URI and mime data type)
üCategory

No comments:

Post a Comment