zoukankan      html  css  js  c++  java
  • Android高手进阶教程(十二)之----Android 在一个应用中如何启动另外一个已安装的应用!!!

    下面是Demo的详细步骤:

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

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

    <?xml version="1.0" encoding="utf-8"?>  
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        android:orientation="vertical"  
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent"  
        >  
      <TextView    
          android:layout_width="fill_parent"   
          android:layout_height="wrap_content"   
          android:text="Welcome to Mr Wei's Blog."  
        />  
      <Button  
          android:id="@+id/button"  
          android:layout_width="fill_parent"   
          android:layout_height="wrap_content"   
          android:text="Start Another Application"  
      />  
      <Button  
          android:id="@+id/start_calender"  
          android:layout_width="fill_parent"   
          android:layout_height="wrap_content"   
          android:text="Start Calendar"  
      />  
    </LinearLayout>

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

    package com.android.tutor;  
    import android.app.Activity;  
    import android.content.ComponentName;  
    import android.content.Intent;  
    import android.os.Bundle;  
    import android.view.View;  
    import android.widget.Button;  
    public class StartAnotherApplicationDemo extends Activity {  
         
        private Button mButton01,mButton02;  
          
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  
              
            mButton01 = (Button)findViewById(R.id.button);  
            mButton02 = (Button)findViewById(R.id.start_calender);  
              
            //-----启动我们自身写的程序------------------  
            mButton01.setOnClickListener(new Button.OnClickListener(){  
                public void onClick(View v) {  
                    //-----核心部分----- 前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名  
                    Intent intent=new Intent();  
                    intent.setComponent(new ComponentName("com.droidnova.android.games.vortex",   
                                                         "com.droidnova.android.games.vortex..Vortex"));  
                    startActivity(intent);  
                }             
            });  
          //-----启动系统自带的应用程序------------------  
            mButton02.setOnClickListener(new Button.OnClickListener(){  
                public void onClick(View v) {  
                    Intent intent=new Intent();  
                    intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));  
                    startActivity(intent);  
                }             
            });  
        }  
    }
    岁月本长而忙者自促;天地本宽而卑者自隘;风花雪月本闲,而劳忧者自冗;天行健,君子以自强不息;地势坤,君子以厚德载物;宠辱不惊,闲看庭前花开花落;去留无意,漫随天外云卷云舒.不妄取,不妄予,不妄想,不妄求,与人方便,随遇而安
  • 相关阅读:
    人生转折点:弃文从理
    人生第一站:大三暑假实习僧
    监听器启动顺序和java常见注解
    java常识和好玩的注释
    182. Duplicate Emails (Easy)
    181. Employees Earning More Than Their Managers (Easy)
    180. Consecutive Numbers (Medium)
    178. Rank Scores (Medium)
    177. Nth Highest Salary (Medium)
    176. Second Highest Salary(Easy)
  • 原文地址:https://www.cnblogs.com/vvning/p/9429756.html
Copyright © 2011-2022 走看看