据我所知,在清单中,我已经正确地声明了接收器元素。但是当我发出广播时,接收器永远不会被调用。日志猫显示。
07-22 23:51:49.181: E/AndroidRuntime(3799): FATAL EXCEPTION: main
07-22 23:51:49.181: E/AndroidRuntime(3799): java.lang.RuntimeException: Unable to instantiate receiver com.example.orderedbroadcastreceiver.HigherPriorityReceiver: java.lang.IllegalAccessException: access to class not allowed
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2333)
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.app.ActivityThread.access$1500(ActivityThread.java:139)
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.os.Looper.loop(Looper.java:137)
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.app.ActivityThread.main(ActivityThread.java:4899)
07-22 23:51:49.181: E/AndroidRuntime(3799): at java.lang.reflect.Method.invokeNative(Native Method)
07-22 23:51:49.181: E/AndroidRuntime(3799): at java.lang.reflect.Method.invoke(Method.java:511)
07-22 23:51:49.181: E/AndroidRuntime(3799): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-22 23:51:49.181: E/AndroidRuntime(3799): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
07-22 23:51:49.181: E/AndroidRuntime(3799): at dalvik.system.NativeStart.main(Native Method)
07-22 23:51:49.181: E/AndroidRuntime(3799): Caused by: java.lang.IllegalAccessException: access to class not allowed
07-22 23:51:49.181: E/AndroidRuntime(3799): at java.lang.Class.newInstanceImpl(Native Method)
07-22 23:51:49.181: E/AndroidRuntime(3799): at java.lang.Class.newInstance(Class.java:1319)
07-22 23:51:49.181: E/AndroidRuntime(3799): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2328)
07-22 23:51:49.181: E/AndroidRuntime(3799): ... 10 more
代码
class HigherPriorityReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "HigherPriorityReceiver", 0).show();
setResultCode(1985);
setResultData("DOB");
//abortBroadcast();
}