Professional Documents
Culture Documents
Forgot your password? API calls are synchronous while intent-based invocations are asynchronous.
Forgot your username?
API calls are compile time binding while intent-based calls are run-time binding
Create an account
Of course, Intents can be made to work exactly like API calls by using what are called
will be explained later. But more often than not, implicit intents are the way to go
Syndication here.
One component that wants to invoke another has to only express its' intent to do
Subscribe to this Feed component that exists and has claimed that it can do such a job through intent-filt
android platform to accomplish the job. This means, both the components are not
existence and can still work together to give the desired result for the end-user.
This invisible connection between components is achieved through the combination
the android platform.
This leads to huge possibilities like:
Programming
The latest & greatest Mix and match or rather plug and play of components at runtime.
in parallel computing.
Replacing the inbuilt android applications with custom developed applications.
Visit our expert blog!
www.drdobbs.com/Go-Parallel Component level reuse within and across applications.
Web/XML Appl. All Android components that wish to be notified via intents should declare intent filters
Generator which intents should go to that component. So, we need to add intent-fil
AndroidManifest.xml file. It looks something like this:
NARM/Network
Application Rendering <?xml version="1.0" encoding="utf-8"?>
Model <manifest xmlns:android=
www.bitech-factory.ch
"http://schemas.android.com/apk/res/android"
Killer Android package="com.bogotobogo.myContacts"
Tweet App
android:versionCode="1"
Killer App with new
android:versionName="1.0">
Live Preview That
<application android:icon="@drawable/icon"
Shows Links In
Tweets-Free android:label="@string/app_name">
www.Twidroyd.com <activity android:name=".myContacts"
android:label="@string/app_name">
<intent-filter>
Latest Comments <action android:name=
"android.intent.action.MAIN" />
ashikch
<category
Bounce Animation
android:name="android.intent.category.LAUNCHER" />
some error!! - I understood the </intent-filter>
code ... </activity>
Aneev </application>
How to Install the A... <uses-sdk android:minSdkVersion="7" />
<uses-permission android:name=
Aneev "android.permission.READ_CONTACTS"/>
10 Open Source Andro... </manifest>
how to compile a code on android.
tel... Note that intent-filter element is under the activity element. In the file, we are declar
JOHNSInez (1) the main activity for this application and (2) the activity is in the LAUNCHER catego
icon in the Android menu. Because this activity is the main one for the application, An
Compile Android kern...
component it should launch when someone chooses the application from the main menu.
reply this topic - We encourage Once we have our intent, we need to pass it to Android and get the child activity to laun
you y... options:
EvangelineVincent33 Call startActivity() with the Intent. This will cause Android to find the best matchin
How to implement you... intent to the activity for handling. The activity will not be informed when the child activit
re - All people deserve wealthy life Call startActivityForResult(), passing it the intent and a number which is unique
... Android will find the best matching activity and pass the intent over to the activity. The
when the child activity is complete via onActivityResult() callback.
InvokedActivity
The InvokingActivity has a button "Invoke Next Activity" which when clicke
InvokedActivity class. The relevant part of the code is here:
androidcore.com/…/627.html 2/11
28/03/2011 Android Applications Tutorial: Intent
InvokedActivity class. The relevant part of the code is here:
package com.bogotobogo.explicitintent;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
and InvokedActivity.java:
package com.bogotobogo.explicitintent;
import android.app.Activity;
import android.os.Bundle;
androidcore.com/…/627.html 3/11
28/03/2011 Android Applications Tutorial: Intent
In the next section, we will see how to work with implicit intents which also needs us
filters.
As described earlier, an implicit intent does not name a target component that shou
Android resolves as to which component is best suited to respond to an Implicit Intent
Basically, an Intent object has the following information (among other things like Compo
flags) which is of interest for implicit intents:
Action
Category
Data
So, Android compares the three (action, category and data) to something called Intent F
androidcore.com/…/627.html 4/11
28/03/2011 Android Applications Tutorial: Intent
by probable target components who are willing to accept Implicit Intent calls. i.e. Inten
any component to advertise its own capabilities to the Android system. This is don
AndroidManifest.xml file.
2. Components willing to receive implicit intents have to declare their ability to han
declaring intent filters.
4. There can be more than one component that declares the same Intent Filters
the same implicit intent. In that case, the user is presented both the compone
choose which one he wants to continue with.
5. We can set priorities for the intent filters to ensure the order of responses.
There are 3 tests conducted in order to match an intent with intent filters:
1. Action Test
2. Category Test
3. Data Test
Finally, we'll look at declaring an implicit intent in one activity which will invoke one of the
platform by matching the intent filters declared by the same.
The ImplicitIntent Activity creates an implicit intent object contacts. This intent object'
However, the action is set to android.content.intent.ACTION_VIEW and
People.CONTENT_URI.
Such an intent matches with the intent filter declared by the view contacts native activity.
So, when we run this application, it displays the native UI for viewing the existing contact
viewContacts.setOnClickListener(new OnClickListener() {
In this manner many of the native applications can be seamlessly invoked as one o
applications through implicit intents.
package com.bogotobogo.implicitintent;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
androidcore.com/…/627.html 5/11
28/03/2011 Android Applications Tutorial: Intent
ViewContacts();
viewContacts.setOnClickListener(new OnClickListener() {
androidcore.com/…/627.html 6/11
28/03/2011 Android Applications Tutorial: Intent
package com.bogotobogo.Launch;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
androidcore.com/…/627.html 7/11
28/03/2011 Android Applications Tutorial: Intent
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.map);
lat=(EditText)findViewById(R.id.lat);
lon=(EditText)findViewById(R.id.lon);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String _lat=lat.getText().toString();
String _lon=lon.getText().toString();
Uri uri=Uri.parse("geo:"+_lat+","+_lon);
startActivity(new Intent(Intent.ACTION_VIEW
}
});
}
}
The button's OnClickListener takes the latitude and longitude, put them into geo scheme
Uri uri=Uri.parse("geo:"+_lat+","+_lon);
Then, starts the activity after creating an intent requesting to view this Uri (ACTION_VIEW
androidcore.com/…/627.html 8/11
28/03/2011 Android Applications Tutorial: Intent
Here is the source for our main activity which is hosting the TabView, IntentTab.java:
package com.bogotobogo.intenttab;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
TabHost host=getTabHost();
host.addTab(host.newTabSpec("one").setIndicator("BoGoToBoGo
setContent(new Intent(this, BoGoBrowser.class)));
host.addTab(host.newTabSpec("two").setIndicator("Android").
setContent(new Intent(this, AndroidBrowser.class)))
}
}
Here, we are using TabActivity as the base class, and so we don't have to use our own la
TabActivity supplies it for us. So, we just get access to the TabHost and add two tabs
Intent that directly refers to another class: BoGoBrowser and AndroidBrowser, respectively
BoGoBrowser.java:
package com.bogotobogo.intenttab;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
browser=new WebView(this);
setContentView(browser);
browser.loadUrl("http://bogotobogo.com");
androidcore.com/…/627.html 9/11
28/03/2011 Android Applications Tutorial: Intent
browser.loadUrl("http://bogotobogo.com");
}
}
AdroidBrowser.java:
package com.bogotobogo.intenttab;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
browser=new WebView(this);
setContentView(browser);
browser.loadUrl("http://www.android.com/");
}
}
androidcore.com/…/627.html 10/11
28/03/2011 Android Applications Tutorial: Intent
Source: bogotobogo
Bookmark with:
Comments (0)
Only registered users can write comments!
Powered by !JoomlaComment 4.0 beta2
androidcore.com/…/627.html 11/11