我在broadcastReceiver中需要一个Activity,但是当我尝试将上下文转换为activity时,它不起作用.
Caused by: java.lang.ClassCastException: android.app.ReceiverRestrictedContext cannot be cast to android.app.Activity
如何从broadcastReceiver获取Activity?
谢谢
解决方法:
How can I get Activity from broadcastReceiver ?
一般来说,你不能. broadcastReceiver独立于Activity.例如,您可以让broadcastReceiver在没有活动运行时接收广播.
但是,您可以在Activity中注册/取消注册broadcastReceiver,并在Activity运行时使用它来接收广播.