在Context中有一个startActivity()方法,在activity中使用startActivity()方法时是没有任何问题的,这是因为activity继承自Context,并且重载了startActivity()方法。但是在Context中直接使用startActivity()方法时会报:
Caused by: 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即可。
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);