开发者

How to listen or poll for an event

I have an Android app in which I'd like to display a fullscreen ad as soon as it becomes available. The ad network's SDK allows me to call a "ready" method to determine 开发者_StackOverflowwhether the ad is ready to display; it returns a boolean. How do I listen for this? Should I be polling this method every few seconds? What's the best Android practice to do this?


The alternative to polling is for the source of the change to generate an event to which you can match a handler, but from you've described, the network's SDK doesn't generate an event. Seems like polling is all you have to work with. You could put the polling code is some small class that just polls. When the polling detects the ad becoming "ready", you can generate an event (I would recommend looking at Google's Guava library at their EventBus) and the rest of your application can respond to the event. You might multiple points that require knowledge of the ad becoming "ready" -- you wouldn't want them all polling independently.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜