Context启动startActivity注意
intent.setFlags()方法中参数的用例:
很多人使用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方法。解决办法是:Java代码中加一个flag,即intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)。这样就可以在新的task里面启动这个Activity了。
Context启动startActivity注意的更多相关文章
- 如何在Spring框架上做开发之Context启动中的“Hook”
1.概述 有些时候,我们需要在spring启动过程中加入一些自己的逻辑,特别是一些基本框架和spring做整合的时候(例如:mybatis-spring-boot-starter),就需要使用Spri ...
- context.startActivity(Intent intent)方法启动activity
在一个Activity环境中用该方法启动一个一个activity不会出任何问题,但在activity之外的其他组件中使用该方法就会出现以下错误: Calling startActivity() fro ...
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag.
https://blog.csdn.net/watermusicyes/article/details/44963773 Context中有一个startActivity方法,Activity继承自C ...
- Context.startActivity出现AndroidRuntimeException
转:http://hi.baidu.com/huaxinchang/item/e1a771cf4d424312b77a2416 昨天做了一个Activity的启动动画,效果是点击桌面图标先出现动画后启 ...
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW _TASK flag.
在Activity中使用startActivity()方法不会有任何限制,因为Activity重载了Context的startActivity()方法.但是如果是在其他地方(如Widget或Servi ...
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI
原代码如下: Intent intent = new Intent(); intent.setClass(mContext, PhotoView.class); Bundle bundle = new ...
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI ...
- Android高仿微信(一)——如何消除启动时的白屏
默认情况下,APP启动时会先把屏幕刷成白色,然后才绘制第一个Activity中的View,这两个步骤之间的延迟会造成启动后先看到白屏(时间大概为1秒左右).时间不长,但是我们也看到,一般的APP时不存 ...
- Android--用DownLoadManager下载完成后启动安装
当我们用系统的服务DownLoadManager下载完成后,系统会发送一个广播,我们只需要注册一个广播,然后在广播里面写如一些相应的操作. 1.注册广播 completeReceiver = new ...
随机推荐
- CentOS 下的MySQL配置
先贴出代码(/etc/my.cnf)如下: #The following options will be passed to all MySQL clients [client] #password ...
- 指定socket文件连接mysql
1.利用ps aux |grep mysql 查看--socket 路径 2.创建软连接.创建文件 3.登录成功
- 使用AlarmManager定时更换壁纸----之一
import android.os.Bundle;import android.app.Activity;import android.app.AlarmManager;import android. ...
- ASP.NET备份还原数据库
核心技术:using System.Data.SqlClient;using System.IO;string SqlStr1 = "Server=(local);DataBase=mast ...
- xml数据解析调研
XML数据解析http://www.tuicool.com/articles/Nraau2(必用) http://www.cnblogs.com/pengyingh/articles/2342699. ...
- 安装VMWare tools,以及解决安装后/mnt中有hgfs但没共享文件的方法
一.首先是安装VMWare tools 安装过程可参考:Installing VMware Tools in an Ubuntu virtual machine 安装成功后,可看的如下信息: ...
- 2.精通前端系列技术之JavaScript模块化开发 seajs(一)
在使用seajs模块化开发之前,直接在页面引用js会容易出现冲突及依赖相关的问题,具体问题如下 问题1:多人开发脚本的时候容易产生冲突(比如全局参数冲突,方法名冲突),可以使用命名空间降低冲突,不能完 ...
- 6.1.2Linux下Socket编程
tcp简单实验 server.c #include <sys/types.h> /* See NOTES */ #include <sys/socket.h> #include ...
- javascript 错误处理
try{ var date=new Date(); date.test();//调用date的未定义的test方法; document.wrire("try块执行结束<br>&q ...
- HQL查询及Hibernate对c3p0连接池的支持
//HQL查询 // auto-import要设置true,如果是false,写HQL时要指定类的全名 //查询全部列 Query query = session.createQuery(" ...