Auto-generate Flow Chart from Java/C++ Codes:

Raptor Flowchart Tutorial For Beginners

Monday, July 23, 2012

Android Intent (Explicit)





Communication between 2 activities happens through an intent. 

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. This is typically used for application internal messages.

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

Note: Here for simplicity sake I tell an activity responds to an intent, it could as well be other types of components.

Now I will jump into the example which you can download from here:

This example has 2 activities:
  1. InvokingActivity
  2. InvokedActivity

The InvokingActivity has a button "Invoke Next Activity" which when clicked explicitly calls the "InvokedActivity" class.
The relevant part of the code is here:
1.Button invokingButton = (Button)findViewById(R.id.invokebutton);
2.invokingButton.setOnClickListener(new OnClickListener() {
3. 
4.public void onClick(View v) {
5.Intent explicitIntent = new Intent(InvokingActivity.this,InvokedActivity.class);
6.startActivity(explicitIntent);
7.}
8.});

As explained in part 1 of the series, this is very much like an API call with compile time binding.

NOTE: The layout for InvokingActivity is defined in main.xml and for InvokedActivity in InvokedActivity.xml. The downloadable example can be opened in Eclipse Ganymede as an android project and can be executed.


from:http://mobile.dzone.com/articles/explicit-intent-android

No comments: