Hello,
I used to use Admob stand-alone library 6.4.x. It had built-in
functionality of changing visible/gone attribute of the ad's view. I've
just switched to Google Play Services library (rev. 29 ; 8487000) and
noticed that this functionality is not supported any more. In this case,
to avoid seeing ugly empty box when the ad is not loaded, I implemented
my solution with AdListener:
onCreate() {
(...)
adView.setVisibility(View.GONE);
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
adView.setVisibility(View.VISIBLE);
}
});
(...)
}
Now we have 3 following scenerios:
a)
Internet on -> application starts (calls onCreate of the activity)
-> ad loads -> adView: visible -> we can see the ad
b)
Internet off -> application starts (calls onCreate of the activity)
-> click on home button (moves app to the background) -> Internet
on -> application recures (moves from the background to the
foreground: calls onStart()/onResume() without onCreate()) -> after
60 sec we get message: "Ad is not visible. Not refreshing ad."
(AdListener:onAdLoaded() hasn't been called)
c) Internet off ->
applicaiton starts (calls onCreate of the activity) -> pull down the
notificiation bar (we are still in the app) -> Internet on ->
after 60 sec we get message: "Ad is not visible. Not refreshing ad."
(AdListener:onAdLoaded() hasn't been called)
On (b) and (c)
scenerio the ad starts to refresh: "Scheduling ad refresh 60000
milliseconds from now" but after 60 sec we get the message: "Ad is not
visible. Not refreshing ad.".
Maybe we should have additional
interface method which is called before AdView checks its visiblity,
e.q. onAdDownloaded() ? So I could move adView.setVisibility(View.VISIBLE) from onAdLoaded() to onAdDownloaded().
After
my several test I assume the problem is with calling loadAd(AdRequest). If I
call adView.loadAd(adRequest) in onCreate() (Activity) method the ad
will be displayed correctly. But if the request of the ad is triggered
by admob itself: from adView.resume() or inner broadcast reciver
(android.net.conn.CONNECTIVITY_CHANG) I will get the message: "Ad is not visible. Not refreshing ad."
Cheers,
Tom