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

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

[java] view plain copy
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns: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="WelcometoMrWei'sBlog."
  11. />
  12. <Button
  13. android:id="@+id/button"
  14. android:layout_width="fill_parent"
  15. android:layout_height="wrap_content"
  16. android:text="StartAnotherApplication"
  17. />
  18. <Button
  19. android:id="@+id/start_calender"
  20. android:layout_width="fill_parent"
  21. android:layout_height="wrap_content"
  22. android:text="StartCalendar"
  23. />
  24. </LinearLayout>

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

[java] view plain copy
  1. packagecom.android.tutor;
  2. importandroid.app.Activity;
  3. importandroid.content.ComponentName;
  4. importandroid.content.Intent;
  5. importandroid.os.Bundle;
  6. importandroid.view.View;
  7. importandroid.widget.Button;
  8. publicclassStartAnotherApplicationDemoextendsActivity{
  9. privateButtonmButton01,mButton02;
  10. publicvoidonCreate(BundlesavedInstanceState){
  11. super.onCreate(savedInstanceState);
  12. setContentView(R.layout.main);
  13. mButton01=(Button)findViewById(R.id.button);
  14. mButton02=(Button)findViewById(R.id.start_calender);
  15. //-----启动我们自身写的程序------------------
  16. mButton01.setOnClickListener(newButton.OnClickListener(){
  17. publicvoidonClick(Viewv){
  18. //-----核心部分-----前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
  19. Intentintent=newIntent();
  20. intent.setComponent(newComponentName("com.droidnova.android.games.vortex",
  21. "com.droidnova.android.games.vortex..Vortex"));
  22. startActivity(intent);
  23. }
  24. });
  25. //-----启动系统自带的应用程序------------------
  26. mButton02.setOnClickListener(newButton.OnClickListener(){
  27. publicvoidonClick(Viewv){
  28. Intentintent=newIntent();
  29. intent.setComponent(newComponentName("com.android.calendar","com.android.calendar.LaunchActivity"));
  30. startActivity(intent);
  31. }
  32. });
  33. }
  34. }

转摘自:http://blog.csdn.net/Android_Tutor/article/details/5596494

更多相关文章

  1. Android中界面中有多个edittext,如何默认让第二个获取焦点
  2. Android调用系统设置
  3. android真机上 conn.getOutputStream()异常 Does not support ou
  4. Android短消息推送启动应用程序(SMS PUSH)(BroadCastReceiver)
  5. 移动web开发常用JavaScript代码
  6. android intent 传递list或者对象
  7. Android(安卓)混淆问题排查
  8. EditText字数限制
  9. android联系人、短信、邮件url总结

随机推荐

  1. putchar在c语言中是什么意思
  2. C语言注释方法有几种?
  3. c语言的阶乘函数如何用递归定义?
  4. 一定要了解的c语言中&与&&的区别
  5. C语言中的标识符由什么组成
  6. C语言 sqrt 是什么意思?
  7. C语言自定义函数返回数组的方法(图文详解)
  8. c语言换行符号是什么?
  9. C语言怎么定义字符串数组
  10. C语言实现删除数组中某个元素