Tuesday, June 19, 2012

Explicit Intent | Android Tutorial for Beginners

Explicit Intent I have described  intents earlier. Here we will discuss about intents, Intents are the methods to make a communication between two activities. means they used to pass data from one activity to other with the help of some variables.

There are 2 types of intents that Android understands.
1. Explicit Intent
2. Implicit Intent

In an Explicit intent, you actually specify the activity that is required to respond to the intent. In other words, you explicitly designate the target component(Activity). This is typically used for application internal messages.
Like we have to pass data from one activity to other activity to accomplish certain processing we used explicit intents.

In an Implicit intent (the main power of the android design), you just declare an intent and leave it to the platform to find an activity that can respond to the intent. Here, you do not declare the target component and hence is typically used for activating components of other applications seamlessly.


Now to explain intents in more detail you can download my example from here.


        Button invokeIntent = (Button)findViewById(R.id.invokeintent);
       
invokeIntent.setOnClickListener(new OnClickListener() {
        

        
public void onClick(View v) {
        
Intent explicitIntent = new Intent(InvokingActivity.this,InvokedActivity.class);
         startActivity(explicitIntent);
        
}
        });

 Note: Here the InvokingActivity activity this class have the layout main.xml and the  InvokedActivity this activity have the InvokedActivity.xml file for there layout. both of the layout you can make by using eclipse.

 In the next part of the series, we will see how to work with implicit intents which also needs us to understand intent-filters.

No comments:

Post a Comment