We've learned how to invoke an activity in a single application of our own. However, one of the more important developments in Android is the use of intent to invoke other application activity. In particular, your application can invoke many "built-in" applications in the system. The so-called "built-in" application, refers to the same level of application, such as browser,phone,sms and so on. For example, if your application needs to open a Web page, you can use the intent object to invoke the browser, and the browser will display the page instead of creating a browser of its own ...
The following example shows how to invoke several of the more commonly used "built-in" applications in the system.
1. Create a project, Intents.
2. Code in 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:orientation=" vertic Al ">
<button android:id=" @+id/btn_webbrowser "android:layout_width=" fill_p Arent "android:layout_height=" wrap_content "android:onclick=" Onclickwebbrowser "android:text=" W EB Browser "/>
<button android:id=" @+id/btn_makecalls "Android:layout_width" = "Fill_parent" android:layout_height= "wrap_content" android:onclick= "Onclickmakecalls" Android: text= "Make Calls"/>
<button android:id= "@+id/btn_showmap" Android:layout_w Idth= "Fill_parent" android:layout_height= "wrap_content" android:onclick= "Onclickshowmap" Androi D:text= "Show Map"/>
<button android:id= "@+id/btn_launchmybrowser" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:onclick= "Onclicklaunchmybrowser" android:text= "Laun" ch my Browser "/> </LinearLayout>
The code in
3. Intentsactivity.java.
public class Intentsactivity extends activity {int request_code = 1; /** called the activity is a.
* * @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main); The public void Onclickwebbrowser (view view) {Intent i = new Intent ("Android.intent.action.
VIEW ");
I.setdata (Uri.parse ("http://www.amazon.com"));
StartActivity (i); public void Onclickmakecalls (view view) {Intent i = new Intent (android.content.intent.a
Ction_dial, Uri.parse ("tel:+651234567"));
StartActivity (i); public void Onclickshowmap (view view) {Intent i = new Intent (Android.content.Intent.ACT
Ion_view, Uri.parse ("geo:37.827500,-122.481670")); StartActivity (i); }
}
4. Debugging.
After the program is started: