从应用A跳转到应用B,  

关键代码如下:  

有以下几个注意点:

1.ComponentName cn = new ComponentName("com.terry", "com.terry.musicActivity");

android.content.ComponentName.ComponentName(String pkg, String cls)

Create a new component identifier.

Parameters:
pkg The name of the package that the component exists in. Can not be
null.
cls The name of the class inside of pkg that implements
the component. Can not be null.
第一个参数:应用B的包名,是String型的;
第二个参数:应用B的类名,要包含包名,即类名的全称,也是String类型的,否则系统会报错。

注意点2:

应用B的12行一定要写上:

  android:exported="true"

这个属性,即暴露出本应用,是其他应用可以访问。

case R.id.btn_main4_2:
// TODO Auto-generated method stub
ComponentName cn = new ComponentName("com.terry", "com.terry.musicActivity");
Intent intent2 = new Intent();
intent2.setComponent(cn);
Toast.makeText(TestAction.this, "跨应用跳转", Toast.LENGTH_SHORT).show();
startActivity(intent2);
break;

  B的清单文件:

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.terry"
android:versionCode="1"
android:versionName="1.0" > <application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<activity
android:name=".musicActivity"
android:exported="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:exported="true"
android:name="com.terry.myActivity2"
android:label="musicPlayer" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.GET_CONTENT" /> <category android:name="android.intent.category.DEFAULT" />
<!--
audio/x-mpeg
<data android:mimeType="*/*" />
-->
<!-- 注册可以打开音乐 -->
<data android:mimeType="audio/mpeg" />
</intent-filter> </activity>
</application> </manifest>

应用之间进行跳转,ComponentName的方式的更多相关文章

  1. 微信小程序详解——页面之间的跳转方式【路由】和参数传递

    微信小程序拥有web网页和Application共同的特征,我们的页面都不是孤立存在的,而是通过和其他页面进行交互,来共同完成系统的功能.今天我们来研究小程序页面之间的跳转方式. 1.先导 在Andr ...

  2. iOS界面之间的跳转方式

    iOS界面之间的跳转方式基本有3种. .改变window的根视图 [self.window setRootViewController:VC]; .模态弹出 [self presentViewCont ...

  3. sprig里的controller之间的跳转的问题

    学习spring的controller,发现controller之间的跳转有些地方搞的不是很清楚,如果通过controller的return语句实现跳转的话,会造成request的丢失:具体怎么回事首 ...

  4. Jsp与servlet之间页面跳转及参数传递实例(转)

    原网址:http://blog.csdn.net/ssy_shandong/article/details/9328985 11. jsp与servlet之间页面跳转及参数传递实例 分类: Java ...

  5. 【Android 复习】 : Activity之间传递数据的几种方式

    在Android开发中,我们通常需要在不同的Activity之间传递数据,下面我们就来总结一下在Activity之间数据传递的几种方式. 1. 使用Intent来传递数据 Intent表示意图,很多时 ...

  6. ASP.NET页面之间传递值的几种方式(转载)

    页面传值是学习asp.net初期都会面临的一个问题,总的来说有页面传值.存储对象传值.ajax.类.model.表单等.但是一般来说,常用的较简单有QueryString,Session,Cookie ...

  7. js 页面之间的跳转、传参以及返回上一页

    js实现html 页面之间的跳转传参以及返回上一页的相关知识点 一.页面之间的跳转传参 1.在页面之间跳转的方式有两种: window.location.href="test.html?nu ...

  8. Servlet——提交表单信息,Servlet之间的跳转

    HTML表单标签:<form></form> 属性: actoion:  提交到的地址,默认为当前页面 method:  表单提交方式 有get和post两种方式,默认为get ...

  9. ASP中页面之间传递值的几种方式

    ASP.NET页面之间传递值的几种方式 页面传值是学习asp.net初期都会面临的一个问题,总的来说有页面传值.存储对象传值.ajax.类.model.表单等.但是一般来说,常用的较简单有QueryS ...

  10. iOS开发-应用之间的跳转及通信

    Update 2016-08-12: 在Github的Demo上增加Mac自定义Url Scheme,可以在Safari上输入特定协议头打开应用,并传递参数) 简介 我们接下来将要实现应用程序之间的跳 ...

随机推荐

  1. Redis的入门Demo(java)

    java代码部分参考了:http://www.runoob.com/redis/redis-java.html 在java中使用Redis,需要引入Redis驱动,就是jedis-2.1.0.jar, ...

  2. PHP发送短信如何实现?

    最近要用php发送和接收短信,用户订单要用短信通知一类的功能,网上看了好多短信平台感觉都不靠谱. 也测试了很多代码,下面把几款PHP发送短信好用的分享给大家: PHP发送短信方法一(比较好,推荐) / ...

  3. java和.net 处理任意格式日期字符串转日期类型,

    1.SimpleDateFormat.parse 把指定格式字符串转日期类型 public static Calendar convToCalender(String str,String templ ...

  4. 11.PHP 教程_PHP Switch 语句

    switch 语句用于根据多个不同条件执行不同动作. PHP Switch 语句 如果您希望有选择地执行若干代码块之一,请使用 switch 语句. 语法 switch (n) { case labe ...

  5. java Serialization and Deserializaton

    This article from JavaTuturial Java provides a mechanism, called object serialization where an objec ...

  6. Linux中fork()函数详解(转)

    一.fork入门知识 一个进程,包括代码.数据和分配给进程的资源.fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同, ...

  7. Java Web 入门(一)使用 Intellij IDEA 14.1.5 创建 Maven Web项目

    1.基础配置 1.1 安装 JDK1.7,配置系统变量:JAVA_HOME 和 Path 1.2 安装 Tomcat 7.0 1.3 安装  Intellij IDEA 14.1.5 1.4 Mave ...

  8. 网络爬虫返回json处理数据

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - Decembe ...

  9. 利用bind搭建dns

    下载bind,我下载的是bind-9.3.1rc1.tar.gz 我下载的文件放在/root目录下 进入目录解压缩 [root@linux root]#tar xfz bind-9.3.1rc1.ta ...

  10. STM32关于优先级设定的理解 NVIC_SetPriority()

    Systick模块初始化配置函数(Systick_config)中设定模块中断优先级的函数为: NVIC_SetPriority((SysTick_IRQn, (1<<__NVIC_PRI ...