在Activity中使用startActivity()方法不会有任何限制,因为Activity重载了Context的startActivity()方法。但是如果是在其他地方(如Widget或Service、BroadcastReceiver中)使用startActivity()方法,就会报错:

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

这时就需要为Intent设置一个FLAG_ACTIVITY_NEW_TASK的flag:

Intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

这样就不会报错了,可以顺利的startActivity()。

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW _TASK flag.的更多相关文章

  1. Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla

      转载于 http://blog.csdn.net/wike163/article/details/6678073    从一个Activity中要通过intent调出另一个Activity的话,需 ...

  2. Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK fla ...

  3. 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 ...

  4. android.util.AndroidRuntimeException Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? com.uethinking.microvideo.manag

    记录学习,网络摘抄 碰到这个异常其实这个上面说的很清楚,加个flag 从一个Activity中要通过intent调出另一个Activity的话,需要使用 FLAG_ACTIVITY_NEW_TASK ...

  5. 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 ...

  6. 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 ...

  7. 兔子--Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK

    错误原因: Activity打开别的Activity的时候会默认把新的Activity放到自己的task中,所以不用指定,可是别的地方就得指定了. 解决的方法:intent.addFlags(Inte ...

  8. Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

    安卓出现如下错误,需要增加FLAG_ACTIVITY_NEW_TASK标志 Intent intent1 = new Intent(getApplicationContext(), CameraAct ...

  9. Calling startActivity() from outside of an Activity

    在Activity中使用startActivity()方法不会有任何限制,因为Activity重载了Context的startActivity()方法.但是如果是在其他地方(如Widget或Servi ...

随机推荐

  1. HDU 5667 Sequence 矩阵快速幂

    官方题解: 观察递推式我们可以发现,所有的fi​​都是a的幂次,所以我们可以对f​i​​取一个以a为底的log,g​i​​=log​a​​ f​i​​ 那么递推式变g​i​​=b+c∗g​i−1​​+ ...

  2. LINUX系统怎么关闭防火墙?

    所谓防火墙指的是一个由软件和硬件设备组合而成.在内部网和外部网之间.专用网与公共网之间的界面上构造的保护屏障.是一种获取安全性方法的形象说法,它是一种计算机硬件和软件的结合,使Internet与Int ...

  3. poj1087 A Plug for UNIX & poj1459 Power Network (最大流)

    读题比做题难系列…… poj1087 输入n,代表插座个数,接下来分别输入n个插座,字母表示.把插座看做最大流源点,连接到一个点做最大源点,流量为1. 输入m,代表电器个数,接下来分别输入m个电器,字 ...

  4. HTTP/2 常见问题回答

    常见问题 为什么修订HTTP? HTTP/1.1已经很好的服务Web超过15个年头,但它的劣势开始显现. 载入一个Web页面比之前占用更多的资源(详情可见HTTP压缩页大小统计),有效的载入这些资源很 ...

  5. mongodb的高级操作(聚合框架)

    group by 查询 不要用java驱动带的group by ,要用2.2版本后的aggregate聚合框架来搞,经过试验速度快一倍 参考 官网:http://docs.mongodb.org/ma ...

  6. java+数据库+D3.js 实时查询人物关系图

    先看下 效果 某个用户,邀请了自己的朋友 ,自己的朋友邀请了其他朋友,1 展示邀请关系,2 点击头像显示邀请人和被邀请人的关系.(网上这种资料很少, 另外很多都是从JSON文件取 数据, 这里是从数据 ...

  7. 在.net Core 中像以前那样的使用HttpContext.Current

    今晚在学习.net Core 的使用 拿来以前项目进行改造最简单的问题就是怎么做到让httpcontext 和以前兼容 ,折腾的很久 终于搞定,纪录一下 .net core中使用了无处不在的注入,看了 ...

  8. hdu2157之矩阵快速幂

    How many ways?? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. 获取datagrid中编辑列combobox的value值与text值

    var ed = $('#dg').datagrid('getEditor', {index:editIndex,field:'productid'}); var productname = $(ed ...

  10. navicate恢复数据

    恢复psc文件,出现记录数为0 不要使用事务,选用遇到错误继续