2

I've implemented Banner Ads in my Android game and I'm wondering what is the 'correct' way to hide these ads? I'm hiding ads during actual game-play and at the moment, I have a couple of simple methods that handle this for me:

public void hideAd(){

    adView.setVisibility(View.GONE);

}

public void showAd(){

    adView.setVisibility(View.VISIBLE);

}

Is this the 'correct' way. I'm currently not pausing and resuming the adView like so:

public void hideAd(){

    adView.setVisibility(View.GONE);
    adView.pause;

}

public void showAd(){

    adView.setVisibility(View.VISIBLE);
    adView.resume();

}

What are the implications (if any) of not using the pause() and resume() methods? Or, indeed the implications (if any) of using these the pause() and resume() methods? Which is the correct/best way?

Sufian
  • 6,405
  • 16
  • 66
  • 120
Zippy
  • 3,826
  • 5
  • 43
  • 96

1 Answers1

3

According to the documentation:

public void pause ()

Pauses any extra processing associated with an AdView and should be called in the parent Activity's onPause() method.

public void resume ()

resumes an AdView after a previous call to pause() and should be called in the parent Activity's onResume() method.

Any Implications?

In your first code snippet, the ads will run when you hide ads affecting your game's performance. (Example, decrease in FPS)

Use the second code snippet to prevent ads from running when you hide ads. This will boost performance by preventing all extra processing such as loading/refreshing ads

Community
  • 1
  • 1
Nana Ghartey
  • 7,901
  • 1
  • 24
  • 26
  • Great answer, this is kind of what I though - just needed confirmation! I was a bit hesitant because as you say it says these methods should be called from the parent activity's onPause and onResume methods (which I am doing), but in my case, I am *also* calling them at other times. – Zippy Jul 07 '14 at 02:12
  • Just a note to anyone reading this, according to my testing, calling Pause() on the AdView seems to reset it's timeout. So if your timeout is 30 seconds, and pause() is called on 29 seconds, when resume() is called, it will be back to 0 seconds. Just setting the visibility leaves the timeout intact to pickup where it left off. – Zippy Jul 16 '14 at 20:08
  • 1
    That's a great discovery. Thanks – Nana Ghartey Jul 16 '14 at 21:23
  • @Zippy I think it's against AdMob's policy to hide the ad or send it below in your view hierarchy. No? – Sufian Oct 01 '15 at 06:39
  • 1
    @Sufian that would make no sense. It would only be against their policy if you hid the ad and kept it refreshing thereby generating false impressions (or impressions that the user could never see). Now that would definitely be against the policy of probably every ad network, and rightly so. – Zippy Oct 01 '15 at 11:16