当我尝试使用广播接收器来监听网络连接状态的变化时,我遇到了 manish.tiw.android.example.activitywrapper cannot be cast to android.app.ContextImpl 运行时异常。你能帮我吗? 堆栈跟踪是 -
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)
最佳答案
我从 github 博客中找到了解决您问题的方法,而不是在我的 Android manifest.xml 文件中注册接收器,而是在自定义应用程序类中声明和注册它。这解决了问题。
关于android - 使用广播接收器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408925/