java.lang.RuntimeException: Unable to resume activity {com.huichenghe.xinlvshuju/com.huichenghe.xinlvshuju.mainpack.MainActivity}: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3139) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3170) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2516) at android.app.ActivityThread.access$900(ActivityThread.java:165) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1375) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:5621) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) 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? at android.app.ContextImpl.startActivity(ContextImpl.java:757) at android.app.ContextImpl.startActivity(ContextImpl.java:737) at android.content.ContextWrapper.startActivity(ContextWrapper.java:331) at com.huichenghe.xinlvshuju.zhy.utils.utils.NetWorkUtil.openSettingNetActivity(NetWorkUtil.java:102) at com.huichenghe.xinlvshuju.mainpack.MainActivity.onResume(MainActivity.java:2433) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1266) at android.app.Activity.performResume(Activity.java:6446) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3129) ... 10 more
解决办法:
启动之前设置flagintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);