源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android Intent启动别的应用实现方法

  • 时间:2021-10-11 16:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android Intent启动别的应用实现方法
我们知道Intent的应用,可以启动别一个Activity,那么是否可以启动别外的一个应用程序呢,答案是可以的。 1、首先我们新建一个Android应用,名为AnotherPro,此应用什么内容都没有,用于被另外一个程序打开。 [img]http://files.jb51.net/file_images/article/201304/20130419162055124.jpg[/img] 2、新建一个工程用于打开上面的应用,程序界面如下 [img]http://files.jb51.net/file_images/article/201304/20130419162055125.jpg[/img] 3、修改程序代码,在onCreate中添加如下代码
anotherPro = (Button) findViewById(R.id.startAnotherPro);calendar = (Button) findViewById(R.id.startCalendar);anotherPro.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.anotherpro", "com.anotherpro.MainActivity"));startActivity(intent);}});calendar.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent();intent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));startActivity(intent);}});
Intent.setComponent(new [b]ComponentName[/b](packageName, mainActivityName));// 第一个参数为应用程序包名,第二个参数为程序启动的Activity
 运行程序,点击AnotherPro将会打开第一个应用;  点击Calendar将会打开系统的日历应用。 [img]http://files.jb51.net/file_images/article/201304/20130419162055126.jpg[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部