Android activity跳轉exception

log:java

 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)android

解決方法;(其實log中已經告訴咱們怎麼改了)app

Context中有一個startActivity方法,Activity繼承自Context,重載了startActivity方法。若是使用 Activity的startActivity方法,不會有任何限制,而若是使用Context的startActivity方法的話,就須要開啓一個新 的task,遇到上面那個異常的,都是由於使用了Context的startActivity方法。解決辦法是,加一個flag。ide

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
oop

相關文章
相關標籤/搜索