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.
精彩评论