Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW _TASK flag.
2015-07-11 08:49
549 查看
在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()。
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()。
相关文章推荐
- c#利用WebClient和WebRequest获取网页源代码的比较
- java初级笔记_GUI
- [Android--UI]TextView的使用学习
- [Android--UI]界面设计原则
- [Android--UI]EditText的使用问题
- [Android--UI]ScrollView使用学习
- [Android--UI]颜色对照表
- continue用法
- [Vision]Vision Acquisition Software安装后IMAQdx,IMAQ函数不出现的问题
- EasyUI的progress对象close方法报错的彻底解决方案
- 【转】Windows和Ubuntu双系统,修复UEFI引导的两种办法
- iOS开发技巧(系列十八:扩展UIColor,支持十六进制颜色设置)
- LeetCode232:Implement Queue using Stacks
- UML建模之时序图(Sequence Diagram)
- UIPopoverController的使用
- How to Build a Scalable Multiplexed Server With NIO
- LeetCode225:Implement Stack using Queues
- 错误号:1364 错误信息:Field 'platId' doesn't have a default value
- 错误号:1364 错误信息:Field 'platId' doesn't have a default value
- 错误代码: 1242 Subquery returns more than 1 row