BroadcastReceiver试图在非有序广播期间返回结果 – 在Android中PACKAGE_ADDED

我在下面给出的代码中得到了这个exception。 我不知道这段代码有什么问题。 请帮我摆脱这个例外。

05-23 23:33:49.853: E/BroadcastReceiver(26895): BroadcastReceiver trying to return result during a non-ordered broadcast 05-23 23:33:49.853: E/BroadcastReceiver(26895): java.lang.RuntimeException: BroadcastReceiver trying to return result during a non-ordered broadcast 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.content.BroadcastReceiver.checkSynchronousHint(BroadcastReceiver.java:783) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.content.BroadcastReceiver.setResultCode(BroadcastReceiver.java:549) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at com.waypedia.rupesh.abhi.RetentionApplicationAddedBroadcastReceiver.onReceive(RetentionApplicationAddedBroadcastReceiver.java:18) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2446) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.app.ActivityThread.access$1700(ActivityThread.java:139) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.os.Handler.dispatchMessage(Handler.java:102) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.os.Looper.loop(Looper.java:136) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at android.app.ActivityThread.main(ActivityThread.java:5102) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at java.lang.reflect.Method.invokeNative(Native Method) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at java.lang.reflect.Method.invoke(Method.java:515) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 05-23 23:33:49.853: E/BroadcastReceiver(26895): at dalvik.system.NativeStart.main(Native Method) 

以下是我的代码:

  public class RetentionApplicationAddedBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { ComponentName comp = new ComponentName(context.getPackageName(), RetentionAddIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); //**LINE 18** } 

  • PACKAGE_REMOVED&PACKAGE_ADDED与PACKAGE_REPLACED Intent Action一起被触发
  • “尝试确定电池电量时,不允许IntentReceiver组件注册接收意图”
  • Android - 如何获得所有可用的意图filter的列表?
  • 如何从Activity.startActivity(意图)select器中排除我自己的活动?
  • 在Android清单中,有多less计划和主机标记可以在intent-filter下进行
  • 使用意图filter不能正常工作,从URL打开Android应用程序
  • 将应用程序与Googlesearch结果和Chrome集成
  • 通过Chrome意图将引荐来源数据传递到Google Play
  • 删除setResultCode() 。 这仅适用于有序广播,如setResultCode()文档中所述 。

    修复它的干净方法是做如下:

     if (isOrderedBroadcast()) { setResultCode(Activity.RESULT_OK); } 

    供参考: https : //groups.google.com/forum/#!topic / android -gcm / JJ_RBzTQFHs