开发者

Execute a callback method from a BroadcastReceiver

I've created a view that installs an alarm via AlarmManager, which will in turn execute a BroadcastReceiver subtype specified by me.

In this BroadcastReceiver, I would like to call a method of my view: I need to clean up after the alarm happened. Can I somehow call my view from the BroadcastReceiver?

I've tried to solve the issue by turning my开发者_StackOverflow中文版 BroadcastReceiver into an inner class, but I couldn't make it work with Context.registerReceiver(), plus I'd rather have it as a top level type for clarity.


Can I somehow call my view from the BroadcastReceiver?

Probably not. Usually AlarmManager alarms invoke receivers registered in the manifest. Those receivers exist on their own, independent from any other Android components.

You can register a receiver via registerReceiver() from your activity, and that receiver could access a View in the activity, and you could possibly target that receiver with AlarmManager, but that will only work while the activity is in the foreground.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜