Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add AdMob ads?
    primarykey
    data
    text
    <p>I've been following this tutorial (<a href="http://www.kilobolt.com/day-7-creating-an-android-game-from-start-to-finish.html" rel="nofollow">http://www.kilobolt.com/day-7-creating-an-android-game-from-start-to-finish.html</a>) for creating an Android game. Now I would like to add AdMob ads to the game in <code>GameScreen</code> Class inside <code>private void drawGameOverUI() {...}</code>.</p> <p>I got the context from <code>SampleGame</code> Class using</p> <pre><code>private static Context context; public Screen getInitScreen() { SampleGame.context = getApplicationContext(); ... } public static Context getAppContext() { return SampleGame.context; } </code></pre> <p>In <code>GameScreen</code> Class inside <code>private void drawGameOverUI()</code> I have this</p> <pre><code>contextGameScreen = SampleGame.getAppContext(); LinearLayout layout = new LinearLayout(contextGameScreen); adView = new AdView(contextGameScreen, AdSize.BANNER, "..."); layout.addView(adView); adView.loadAd(new AdRequest()); </code></pre> <p>but I got this error <code>"Cannot resolve constructor 'AdView(android.content.Context, com.google.ads.AdSize, java.lang.String)'"</code> for <code>(contextGameScreen, AdSize.BANNER, "...");</code>.</p> <p>On Google Developers (<a href="https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#android" rel="nofollow">https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals#android</a>) they use 'this', but when I use <code>(this, AdSize.BANNER, "...");</code> I got the error <code>"Cannot resolve constructor 'AdView(com.name.GameScreen, com.google.ads.AdSize, java.lang.String)'"</code>.</p> <p>Can you please help me with this, how to solve this error, and to get this to work? This means alot to me. And also what exactly is 'this'?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload