Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
2014-06-06 11:31
691 查看
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
在调用Context.startActivity(intent)的时候报错,信息如下:这是因为,在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 intent = new Intent(); intent.setClass(mContext, PhotoView.class); Bundle bundle = new Bundle(); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent);
在前面加上intent.addFlags(FLAG_ACTIVITY_NEW_TASK)或者使用Activity.startActivity(intent)
相关文章推荐
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag
- 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
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla
- Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla
- 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_ACTIVITY_NEW_TASK flag
- Calling startActivity() from outside of an Activity context requires the FLA
- context.startActivity时报错startActivity() from outside of an Activity context require the FLAG_ACTIVITY_NEW_TASK flag
- startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW flag
- AndroidRuntimeException “Calling startActivity() from outside of an Activity context requires the FL
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI
- startActivity时报错Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVI