android异常Calling startActivity() from outside of an Activity

如果从不是Activity的Context来startActivity,比如从service,application的Context来开启会报异常:

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


解决方案:告诉系统要创新出给我重新创建任务栈来放俺的目标Activity

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

你可能感兴趣的:(startactivity,calling,android异常,startActivit)