很多人使用startActivity时候,会碰到如下的异常:
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);
这样就可以再新的task里面启动这个Activity了。
分享到:
相关推荐
W/System.err: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? W/System.err: at...
MySql5.7.20安装过程中报错 This application requires Visual Studio 2013 Redistributable. Please install the Redistributable then run this installer again. 的解决办法.报错如下: 1: Action 10:59:21: ...
v7包解决importandroid.support.annotation.RequiresApi
前端开源库-find-requiresfind requires,find all require()调用。使用直接扫描程序和eSprima AST解析器支持快速、可靠的实现
主要介绍了Spring异常捕获且回滚事务解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
error: #error "Qt requires C++11 support c++0x, c++11的解决办法 如果你是用makefile编译还好解决些,但是如果你是用CMake编译,你还得变成CMake的写法. 不过低层原理都一样,都是在g++上作文章. 我来告诉你makefile...
NULL 博文链接:https://yxhcquedu.iteye.com/blog/861110
关于Android Studio升级为V4.1.1Activity不能创建解决方法
Apache JMeter 5.1.1 (Requires Java 8+),需要jdk8以上的版本。
2、Propagation.REQUIRES_NEW 无论何时自身都会开启事务 3、Propagation.SUPPORTS 自身不会开启事务,在事务范围内则使用相同事务,否则不使用事务 4、Propagation.NOT_SUPPORTED 自身不会开启事务,...
安装 mysql5.7时提示:This application requires Visual Studio 2013 Redistributable. Please install the Redistributable then run this installer again. 需要安装指定版本的Microsoft Visual C++ ...
This paper describes the basic processing model and architecture of Aurora, a new system to manage data streams for monitoring applications. Monitoring applications differ substantially from ...
解决mysql 5.7.x 安装报错 This application requires Visual Studio 2013 Redistributable 将压缩包解压,先安装vcredist_x64后尝试重新安装mysql 5.7.x ,假如依然报错,然后安装vcredist_x86后再次安装mysql 问题...
Eclipse/sts启动时,The Maven Integration requires that Eclipse be running in a JDK
NULL 博文链接:https://zzc1684.iteye.com/blog/2237179
。Apache JMeter 5.1.1 (Requires Java 8+),需要jdk8以上的版本。
解决eclipse加载android adt时候的版本过高问题!
JMeter 最新版
Apache JMeter 5.4.3 Requires Java 8+