启动其他APK的Activity方法 (转至http://www.cnblogs.com/lijunamneg/archive/2013/02/26/2934060.html)
有两个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)的更多相关文章
- apache启用gzip压缩方法--转载自http://www.cnblogs.com/linzhenjie/archive/2013/03/05/2943635.html
一.gzip介绍 Gzip是一种流行的文件压缩算法,现在的应用十分广泛,尤其是在Linux平台.当应用Gzip压缩到一个纯文本文件时,效果是非常明显的,大约可以减少70%以上的文件大小.这取决于文件中 ...
- (转)linux自定义开机启动服务和chkconfig使用方法
原文:https://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html linux自定义开机启动服务和chkconfig使用方法 1. 服 ...
- 启动一个新的activity并携带数据,返回数据给上一个activity
一.在启动一个新的activity的时候可以通过Intent携带数据,通过Intent.putExtra()方法通过键值对的形势装入数据.在新启动的activity中通过 getI ...
- android 21 隐式意图启动系统预定义activity
Intent intent=new Intent(LoginActivity.this, MainActivity.class);//显示意图启动,显示从一个activity到另一个activity, ...
- (转)从android一个apk中启动第三方apk应用
从android一个apk中启动第三方apk应用 我们在开发中,经常遇到遇到在一个apk中要去运行另外一个apk,就像我们windows一样,搞一个快捷方式一样,那怎么实现呢? 问题的核心点在于我们要 ...
- android定义启动唯一apk
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...
- phpStudy启动失败时的解决方法
phpStudy启动失败时的解决方法 phpStudy启动失败,原因一是防火墙拦截,二是80端口已经被别的程序占用,如IIS,迅雷等:三是没有安装VC9运行库,php和apache都是VC9编译.解决 ...
- 增加eclipse启动的Tomcat内存的方法 tomcat内存增加
增加eclipse启动的Tomcat内存的方法 Tomcat一般默认情况下最大最优内存设置为2G 这种情况下,修改Tomcat\bin\catalina.bat,添加如下内容 set JAVA_OPT ...
- 安装、设置与启动MySql绿色版的方法
原文:安装.设置与启动MySql绿色版的方法 1.解压 mysql-noinstall-5.1.30-win32.zip(下载地址http://dev.mysql.com/downloads/mysq ...
随机推荐
- (转)使用异步Python 3.6和Redis编写快速应用程序
转自:http://mp.weixin.qq.com/s?__biz=MjM5NzU0MzU0Nw==&mid=2651374524&idx=1&sn=d289aa7aa484 ...
- 将不同级别的logging 日志信息写入不同文件
将不同级别的logging 日志信息写入不同文件 # -*- coding: utf-8 -*- import os import time from logging.handlers import ...
- 【Android】Intent解读
Intent 的作用 Intent 是一个将要执行的动作的抽象的描述,一般来说是作为参数来使用,由Intent来协助完成android各个组件之间的通讯. 比如说调用startActivity()来启 ...
- 【Acm】八皇后问题
八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题. 其解决办法和我以前发过的[算法之美—Fire Net:www.cnblogs.com/lcw/p/3159414.html]类似 题目:在8 ...
- 【Acm】算法之美—Anagrams by Stack
题目概述:Anagrams by Stack How can anagrams result from sequences of stack operations? There are two seq ...
- LeetCode: Best Time to Buy and Sell Stock II 解题报告
Best Time to Buy and Sell Stock IIQuestion SolutionSay you have an array for which the ith element i ...
- jQuery 实现前端模糊匹配与首字母搜索
实现效果 源码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...
- C语言 · 字符串变换
算法训练 字符串变换 时间限制:1.0s 内存限制:256.0MB 问题描述 相信经过这个学期的编程训练,大家对于字符串的操作已经掌握的相当熟练了.今天,徐老师想测试一下大家对于字符 ...
- [进程]kill 9和15,以及pkill, killall
转自:https://www.cnblogs.com/liuhouhou/p/5400540.html 大家对kill -9 肯定非常熟悉,在工作中也经常用到.特别是你去重启tomcat时.可是多半看 ...
- [RTC]系统时间NTP和RTC同步,Debian的时区配置
转自:http://www.cnblogs.com/jiu0821/p/5999566.html Debian的时区配置 一. 修改时区 1. 查看当前时区 命令 : "date -R&qu ...