使用广播接收器时出错

时间:2016-07-16 07:33:08

标签: android networking broadcastreceiver android-context

我收到manish.tiw.android.example.activitywrapper无法转换为android.app.ContextImpl尝试使用广播接收器侦听网络连接状态的变化时的运行时异常。你能帮帮我吗? Stacktrace是 -

java.lang.RuntimeException: Unable to start receiver com.amazonaws.cognito.sync.demo.NetworkChangeReceiver: java.lang.ClassCastException: manish.tiw.android.example.activitywrapper cannot be cast to android.app.ContextImpl
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2452)
at android.app.ActivityThread.access$1600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1356)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5283)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

我从github博客找到了你的问题的解决方案,不是在我的Android manifest.xml文件中注册接收器,而是在自定义Application类中声明并注册它。这解决了这个问题。