Tuesday, 18 October 2016

Android | Intents

INTENTS

Intents are used to start and stop activities and services, or to broadcast message, or to request an action to be performed on a particular piece of data.
Intent is a parameter used in start activity() method. When the start activity() method called with intent parameter, the android system match the intent action with activity on android system. That activity is then launch.
An intent is represented android. Content . intent class. It is in the content package because intents can be used to access content provides.
“an intent is an abstract description of an operation to be performed” 
an intent object is basically a passive data object. There are 3 types od intent objects that can be used inside the android OS to communication with activities, services and broadcast receiver. In fact, there is one intent type for each intent object based message can contain up to 7 kinds of information parts
  1. Name: The name of the class the intent are targeting bb using package name and class name
  2. Action:  A predefined type of action that is to be performed
  3. Data: The actual data such as phone number to call
  4. Category: Android has predefined intents that are the parts of OS that are divided into various types of categories for easy access.
  5. Type: It specify type of data using a MIME format
  6. Flag: This allow on\off flags to be sent with the intents
  7. Extras: It all extra information included in intent

Passing Information with Intents

Intents can be used to passed data between activities. You can use an intent to include addition of data called extras, within the intent. For this put Extra() method will be used
 Example : 
Intentin = newIntent (getApplicationContext (), HelpActivity.class);
In.putExtra(com.androidbook.chippy.LEVEL, 23);
startActivity(in)
when help activity class launches, get Intent() method used to retrieve the intent. Then extra information can be extracts using appropriate method.
Intent nn = getIntent();
Int helpLevel= nn.getIntExtra(com.androidbook.chippyLEVEL,23)

" parent activity that launch sub activity use startActivityForResult() the result is passed as a parameter to the onActivityResult()"

Method with an Intent parameter.

  • Use Intent to launch other application
  • Launching the build in web browser and supply a URL address
  • Launching the web browser and supply a search string
  • Launching the build in Dialer Application
  • Launching the build in  Application
  • Launching the ringtone picker

There are two broadcast categories of intents
Explicit intents use component portion of intent object and generally use these when working with application you have developed

Implicit intents they don’t specify components within intent object












No comments:

Post a Comment