【问题标题】:How do i get rid of these Log cat errors..?我如何摆脱这些 Log cat 错误..?
【发布时间】:2013-04-02 17:50:00
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2017-01-25
      相关资源
      最近更新 更多