BroadcastReceiver пытается вернуть результат во время неупорядоченной трансляции-пакет добавлен в Android
Я получаю это исключение в моем приведенном ниже коде. я понятия не имею, что не так с этим кодом. Пожалуйста, помогите мне избавиться от этого исключения.
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.access00(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**
}
2 ответов
удалить setResultCode()
. Это только для использования с упорядоченной трансляцией, как описано в документация setResultCode()
.
чистый способ исправить это было бы сделать следующим образом:
if (isOrderedBroadcast()) {
setResultCode(Activity.RESULT_OK);
}
для справки:https://groups.google.com/forum#!тема / android-gcm/0J_RBzTQFHs