我如何摆脱这些Log cat错误..?

时间:2013-04-02 17:50:00

标签: android thread-safety android-activity android-logcat android-context

在运行我的Android应用程序时遇到以下错误...请帮助我解决它没有任何意义..

04-02 23:01:33.375: E/AndroidRuntime(4779): FATAL EXCEPTION: main
04-02 23:01:33.375: E/AndroidRuntime(4779): java.lang.RuntimeException: Unable to start service com.salesforce.samples.templateapp.MyServices@413c8878 with Intent { cmp=com.salesforce.samples.templateapp/.MyServices }: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2403)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.app.ActivityThread.access$1900(ActivityThread.java:127)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1221)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.os.Looper.loop(Looper.java:137)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.app.ActivityThread.main(ActivityThread.java:4448)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at java.lang.reflect.Method.invokeNative(Native Method)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at java.lang.reflect.Method.invoke(Method.java:511)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at dalvik.system.NativeStart.main(Native Method)
04-02 23:01:33.375: E/AndroidRuntime(4779): 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?
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.app.ContextImpl.startActivity(ContextImpl.java:877)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:276)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at com.salesforce.samples.templateapp.MyServices.onStartCommand(MyServices.java:43)
04-02 23:01:33.375: E/AndroidRuntime(4779):     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2386)

1 个答案:

答案 0 :(得分:1)

当您从服务中调用startActivity时,请指定FLAG_ACTIVITY_NEW_TASK。否则你会继续崩溃。