首页 > 代码库 > 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
从一个Activity中要通过intent调出另一个Activity的话,需要使用 FLAG_ACTIVITY_NEW_TASK
否则的话,会有force close:
03-01 18:49:37.888 E/AndroidRuntime( 2706): FATAL EXCEPTION: main
03-01 18:49:37.888 E/AndroidRuntime( 2706): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS:
如果调出的Activtivity只是一个功能片段,并没有实际的意义,也没有必要出现在长按Home键调出最近使用过的程序类表中,那么使用FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Intent intent = new Intent(this, WaitingFallBackDialog.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK fla