有两个app,分别叫做App1和App2。
App1包含两个Activity,分别叫做App1_A和App1_B.其中App1_A是入口Activity.
也就是App1_A设置intent-filter,action为<action android:name="android.intent.action.MAIN" />
App2只有一个Activity,叫做App2_A。
现在在App2_A中通过startActivity启动App1_A是没问题的.但是启动App1_B的时候报了fc错误。
logcat如下:
08-03 02:23:44.119: WARN/ActivityManager(64): Permission denied: checkComponentPermission() reqUid=10030
08-03
02:23:44.119: WARN/ActivityManager(64): Permission Denial: starting
Intent { act=android.intent.action.VIEW cmp=com.hello/.activity2 } from
ProcessRecord{407c8bc8 665:com.fileExplorer/10032} (pid=665, uid=10032)
requires null

用法如下:
Intent intent = new Intent();
ComponentName componentName = new ComponentName("com.hello","com.hello.App1_A");//这个没问题
//ComponentName componentName = new ComponentName("com.hello","com.hello.App1_B");//这个报错
intent.setComponent(componentName);
startActivity(intent);

解决方法:
(1)
通过隐式intent调用方法实现,需要在被调用的activity的manifest文件中添加
<intent-filter>
<action android:name="com.example.project.SHOW_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
在StartActivity(it)之前,设定该intent对应的action(com.example.project.SHOW_ACTIVITY)
Intent intent = new Intent();
intent.setAction(action);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);推荐使用

利用setAction方法启动Activity还有一个好处就是不需要知道包名和Activity类名,只需要知道action就可以隐式的启动activity

(2)
即使直接指定了目标activity的ComponentName,跨应用的activity调用也要至少给目标activity指定一个带action的filter。如:
<intent-filter>
<action android:name="" />
</intent-filter>
action name为空即可。
(3)给被调用的Activity增加一个带action的filter,如下:
<intent-filter>
<action android:name="com.sdmc.ottplayer.uercenter" />
</intent-filter>
然后可以通过隐式Intent来调用,而不用使用intent.setComponent方法,如下就OK了(但是经过验证,这种方法只是对APK的入口activity有用,对普通的没用,和上面的问题一样无法解决:启动其他APK的非入口activity)
Intent i = new Intent("com.sdmc.ottplayer.uercenter");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

异常处理:
Caused by: android.util.AndroidRuntimeException:
Calling startActivity() from outside of an Activity context requires
the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
Context中有一个startActivity方法,Activity继承自Context,重载了startActivity方法。
如果使用 Activity的startActivity方法,不会有任何限制,
而如果使用Context的startActivity方法的话,就需要开启一个新 的task,遇到上面那个异常的,都是因为使用了Context的startActivity方法。
解决办法是,加一个flag。intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

Intent intent = new Intent();
intent.setClass(mContext, VideoPlayer.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);

启动其他APK的Activity方法 (转至http://www.cnblogs.com/lijunamneg/archive/2013/02/26/2934060.html)的更多相关文章

  1. apache启用gzip压缩方法--转载自http://www.cnblogs.com/linzhenjie/archive/2013/03/05/2943635.html

    一.gzip介绍 Gzip是一种流行的文件压缩算法,现在的应用十分广泛,尤其是在Linux平台.当应用Gzip压缩到一个纯文本文件时,效果是非常明显的,大约可以减少70%以上的文件大小.这取决于文件中 ...

  2. (转)linux自定义开机启动服务和chkconfig使用方法

    原文:https://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html linux自定义开机启动服务和chkconfig使用方法 1. 服 ...

  3. 启动一个新的activity并携带数据,返回数据给上一个activity

    一.在启动一个新的activity的时候可以通过Intent携带数据,通过Intent.putExtra()方法通过键值对的形势装入数据.在新启动的activity中通过           getI ...

  4. android 21 隐式意图启动系统预定义activity

    Intent intent=new Intent(LoginActivity.this, MainActivity.class);//显示意图启动,显示从一个activity到另一个activity, ...

  5. (转)从android一个apk中启动第三方apk应用

    从android一个apk中启动第三方apk应用 我们在开发中,经常遇到遇到在一个apk中要去运行另外一个apk,就像我们windows一样,搞一个快捷方式一样,那怎么实现呢? 问题的核心点在于我们要 ...

  6. android定义启动唯一apk

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...

  7. phpStudy启动失败时的解决方法

    phpStudy启动失败时的解决方法 phpStudy启动失败,原因一是防火墙拦截,二是80端口已经被别的程序占用,如IIS,迅雷等:三是没有安装VC9运行库,php和apache都是VC9编译.解决 ...

  8. 增加eclipse启动的Tomcat内存的方法 tomcat内存增加

    增加eclipse启动的Tomcat内存的方法 Tomcat一般默认情况下最大最优内存设置为2G 这种情况下,修改Tomcat\bin\catalina.bat,添加如下内容 set JAVA_OPT ...

  9. 安装、设置与启动MySql绿色版的方法

    原文:安装.设置与启动MySql绿色版的方法 1.解压 mysql-noinstall-5.1.30-win32.zip(下载地址http://dev.mysql.com/downloads/mysq ...

随机推荐

  1. 每日英语:China's Bigger Innovation Problem

    Last month's Third Plenum meeting of Chinese leaders seemed to signal Beijing's intention to experim ...

  2. 每日英语:Pediatricians Set Limits on Screen Time

    Parents should ban electronic media during mealtimes and after bedtime as part of a comprehensive 'f ...

  3. 用ubuntu的grpb2引导Remix OS或Phoenix OS

    Remix OS游戏版,这里下载:http://youxi.jide.com/ 安装简单.我这里要解决的是安装后用ubunu的grub2菜单去引导它. 方法如下: 进入ubuntu系统里修改其grub ...

  4. DLL中获取主程序句柄

    一.问题由来及说明 在实际编程中遇到一些系统模块(或API)调用初始化需要窗口句柄,在主程序中(MFC或者win32)都可以很容易获得,比如mfc中可以直接调用AfxGetMainWnd().GetS ...

  5. Redis 相关操作

    1.安装 下载地址:http://www.redis.cn/ 在使用Redis时,开始就遇到了问题,客户端打不开,原因是需要先开启服务端,这需要先配置—— 1.下载好redis安装包,解压安装之后,复 ...

  6. Android studio动态调试

    Reference:  http://cstsinghua.github.io/2016/06/13/Android%20studio%E5%8A%A8%E6%80%81%E8%B0%83%E8%AF ...

  7. 【转】 Java中的变量赋值和参数传递

    原文地址:http://blog.csdn.net/whmii/article/details/3363667 变量赋值和参数传递是java中两个容易让人迷惑的问题.对于原始类型(primitives ...

  8. thinkphp继承高级model后的乐观锁运用(测试中)

    <?php class IndexAction extends Action { private $d_user; private $user; private $arr; public fun ...

  9. C#中Attribute和Property

    XAML是XML派生而来的语言,所以很多XML中的概念在XAML中是通用的. 为了表示同类标签中的某个标签与众不同,可以给它的特征(Attribute)赋值,为特征值赋值的语法如下: 非空标签:< ...

  10. JAVA是否可以作脚本语言呢

    答:是可以的. 只是叫另一个名字-beanshell.印象里她好像还是第一款jvm语言.应该挺多年没更新了. 我之所以知道它,是当年折腾jEdit这款编辑器较多,它的内置脚本引擎使用的就是beansh ...