0

我在运行我的 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)
4

1 回答 1

1

当您从服务调用 startActivity 时,请像上面所说的那样指定 FLAG_ACTIVITY_NEW_TASK。否则你会继续崩溃。

于 2013-04-02T17:52:17.617 回答