Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3428112
  • 博文数量: 864
  • 博客积分: 14125
  • 博客等级: 上将
  • 技术积分: 10634
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-27 16:53
个人简介

https://github.com/zytc2009/BigTeam_learning

文章分类

全部博文(864)

文章存档

2023年(1)

2021年(1)

2019年(3)

2018年(1)

2017年(10)

2015年(3)

2014年(8)

2013年(3)

2012年(69)

2011年(103)

2010年(357)

2009年(283)

2008年(22)

分类: Java

2010-11-16 11:33:32

而为了能让大家更加容易的理解,我写了一个简单的Demo,我们的程序有俩个按钮,其中一个点击会启动我自己写的应用(一个3D应用为例),而另外一个按钮会启动系统自带的应用(如,日历,闹钟,计算器等等).这里我一日历为例子!

首先看一下我们的效果图(点击第一个按钮为例):

 

下面是Demo的详细步骤:

一、新建一个Android工程命名为StartAnotherApplicationDemo.

二、修改main.xml布局,代码如下:

  1. "1.0" encoding="utf-8"?>  
  2. ""  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7.     android:layout_width="fill_parent"   
  8.     android:layout_height="wrap_content"   
  9.     android:text="Welcome to Mr Wei's Blog."  
  10.     />  
  11.     android:id="@+id/button"  
  12.     android:layout_width="fill_parent"   
  13.     android:layout_height="wrap_content"   
  14.     android:text="Start Another Application"  
  15. />  
  16.     android:id="@+id/start_calender"  
  17.     android:layout_width="fill_parent"   
  18.     android:layout_height="wrap_content"   
  19.     android:text="Start Calendar"  
  20. />  
  21.   

三、修改主程序StartAnotherApplicationDemo.java代码如下:

  1. package com.android.tutor;  
  2. import android.app.Activity;  
  3. import android.content.ComponentName;  
  4. import android.content.Intent;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.widget.Button;  
  8. public class StartAnotherApplicationDemo extends Activity {  
  9.      
  10.     private Button mButton01,mButton02;  
  11.       
  12.     public void onCreate(Bundle savedInstanceState) {  
  13.         super.onCreate(savedInstanceState);  
  14.         setContentView(R.layout.main);  
  15.           
  16.         mButton01 = (Button)findViewById(R.id.button);  
  17.         mButton02 = (Button)findViewById(R.id.start_calender);  
  18.           
  19.         //-----启动我们自身写的程序------------------  
  20.         mButton01.setOnClickListener(new Button.OnClickListener(){  
  21.             public void onClick(View v) {  
  22.                 //-----核心部分----- 前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名  
  23.                 Intent intent=new Intent();  
  24.                 intent.setComponent(new ComponentName("com.droidnova.android.games.vortex",   
  25.                                                      "com.droidnova.android.games.vortex..Vortex"));  
  26.                 startActivity(intent);  
  27.             }             
  28.         });  
  29.       //-----启动系统自带的应用程序------------------  
  30.         mButton02.setOnClickListener(new Button.OnClickListener(){  
  31.             public void onClick(View v) {  
  32.                 Intent intent=new Intent();  
  33.                 intent.setComponent(new ComponentName("com.android.calendar""com.android.calendar.LaunchActivity"));  
  34.                 startActivity(intent);  
  35.             }             
  36.         });  
  37.     }  
  38. }  

四、执行之,将得到如上效果!

阅读(568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~