Android advanced tutorial (12)-How to start another installed app in an app !!!

Source: Internet
Author: User

Jimmy asked me this evening how to start another installed application through an event in an application. So I 'd like to share it with you!

To make it easier for everyone to understand, I wrote a simple demo. Our program has two buttons, one click will start my own application (a 3D application is used as an example), and the other button will start the application (such as calendar, alarm clock, calculator, and so on) that comes with the system ). here is an example of my calendar!

 

First, let's take a look (click the first button as an example ):

 


 

 

 

The detailed steps of the demo are as follows:

 

1. Create an android project named startanotherapplicationdemo.

 

2. Modify the main. xml layout. The Code is as follows:

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "welcome to Mr Wei's blog. "<br/> <button <br/> Android: Id =" @ + ID/button "<br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "start another application" <br/> <button <br/> Android: Id = "@ + ID/start_calender" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "Start Calendar" <br/> </linearlayout> <br/>

 

3. Modify the main program startanotherapplicationdemo. Java code as follows:

 

Package COM. android. tutor; <br/> Import android. app. activity; <br/> Import android. content. componentname; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. widget. button; <br/> public class startanotherapplicationdemo extends activity {</P> <p> private button mbutton01, mbutton02; </P> <p> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> mbutton01 = (button) findviewbyid (R. id. button); <br/> mbutton02 = (button) findviewbyid (R. id. start_calender); </P> <p> // ----- start the program ---------------- <br/> mbutton01.setonclicklistener (New button. onclicklistener () {<br/> Public void onclick (view v) {<br/> // ----- core section ----- the first parameter is the package name of the application, the last one is the main activity name of the application <br/> intent = new intent (); <br/> intent. setcomponent (New componentname ("com. droidnova. android. games. vortex ", <br/>" com. droidnova. android. games. vortex .. vortex "); <br/> startactivity (intent); <br/>}< br/> }); <br/> // ----- start the built-in application ------------------ <br/> mbutton02.setonclicklistener (New button. onclicklistener () {<br/> Public void onclick (view v) {<br/> intent = new intent (); <br/> intent. setcomponent (New componentname ("com. android. calendar "," com. android. calendar. launchactivity "); <br/> startactivity (intent); <br/>}< br/>}); <br/>}< br/>}

 

 

4. Execute the command to get the above effect!

 

 

Now we are here today. It's late at night, and we're done to bed! What do you not understand? I hope you can leave more comments. I will answer them with patience! Thank you ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.