We already know that an activity invokes another activity by using the intent object. In order to be able to respond to other activity, you also need to configure <intent-filter> elements in Androidmanifest.xml, specifying both action and category. For example:
<intent-filter >
<action android:name= "com.manoel.SecondActivity"/> <category android:name
= "Android.intent.category.DEFAULT"/>
</intent-filter>
1. Create a new project, creating a class: Mybrowseractivity.java. Also create an XML file in Res/layout: Brwoser.xml.
2. Androidmanifest.xml
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/"
Android "package=" Com.manoel.Intents "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "/> <uses-permission android:name=" Android.permission.CALL_PHON
E "/> <uses-permission android:name=" Android.permission.INTERNET "/> <application
android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" > <activity Android:label= "@string/app_name" Android:name= ". Intentsactivity "> <intent-filter > <action android:name=" android.intent . Action. MAIN "/> <category android:name=" Android.intent.category.LAUNCHER "/> </
Intent-filter> </activity>
<activity android:name= ".
Mybrowseractivity "android:label=" @string/app_name "> <intent-filter> <action android:name= "Android.intent.action.VIEW"/> <action android:name= "com. Manoel.
Mybrowser "/> <category android:name=" Android.intent.category.DEFAULT "/>"
<data android:scheme= "http"/> </intent-filter> </activity> </application> </manifest>
3. Add a button element to the Main.xml.
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android=
"http://schemas.android.com/apk/" Res/android "
android:layout_width=" fill_parent "
android:layout_height=" fill_parent "
android:o" rientation= "vertical" >
<button
android:id= "@+id/btn_launchmybrowser"
Fill_parent "
android:layout_height=" wrap_content "
android:onclick=" Onclicklaunchmybrowser
" android:text= "Launch my Browser"/>
</LinearLayout>
4.intentsactivity.java
The public class Intentsactivity
extends activity {
/** called the
' when ' is the ' The activity ' is a-a-created />public void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
public void Onclicklaunchmybrowser (view view) {
Intent i = new Intent ("Com.manoel.MyBrowser");
I.setdata (Uri.parse ("http://www.amazon.com"));
StartActivity (i);
}
}