现在的位置: 首页 > 综合 > 正文

Android 在一个应用中如何启动另外一个已安装的应用

2013年10月13日 ⁄ 综合 ⁄ 共 1530字 ⁄ 字号 评论关闭

如何在一个应用中 通过某个事件,而去启动另外一个已安装的应用。

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

 

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

 

  

 

 

下面是Demo的详细步骤:

 

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

 

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

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <TextView    
  8.     android:layout_width="fill_parent"   
  9.     android:layout_height="wrap_content"   
  10.     android:text="Welcome to Mr Wei's Blog."  
  11.     />  
  12. <Button  
  13.     android:id="@+id/button"  
  14.     android:layout_width="fill_parent"   
  15.     android:layout_height="wrap_content"   
  16.     android:text="Start Another Application"  
  17. />  
  18. <Button  
  19.     android:id="@+id/start_calender"  
  20.     android:layout_width="fill_parent"   
  21.     android:layout_height="wrap_content"   
  22.     android:text="Start Calendar"  
  23. />  
  24. </LinearLayout>  

 

三、修改主程序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);  

抱歉!评论已关闭.