log:
java.lang.RuntimeException:
Unable to start receiver com.vkoov.csipsimple.service.OutgoingCall: 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.handleReceiver(ActivityThread.java:2126)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4426)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
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:847)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
at com.vkoov.csipsimple.service.OutgoingCall.onReceive(Unknown Source)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2119)
解决方法;(其实log中已经告诉我们怎么改了)
Context中有一个startActivity方法,Activity继承自Context,重载了startActivity方法。如果使用 Activity的startActivity方法,不会有任何限制,而如果使用Context的startActivity方法的话,就需要开启一个新 的task,遇到上面那个异常的,都是因为使用了Context的startActivity方法。解决办法是,加一个flag。
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
来源:oschina
链接:https://my.oschina.net/u/1189048/blog/225548