Reputation: 737
I transfer context into a Specific Activity in onReceive()of BroadcastReceiver, like MyActivity ma = (MyActivity) context;
. I want to call a method in Activity, but when I transfer context, it has this error: ClassCastException error
. Before, in another project, I transferred the service without problem. Why does it give an error?
Upvotes: 1
Views: 222
Reputation: 12350
because context
variable in onReceive
method (docs) is The Context in which the receiver is running
. ( you can't cast it to activity
because receiver is running in application context, I think.)
You can organize communication between application components via handlers
or via broadcasting custom intents.
Upvotes: 2