title: Google AdMob Ads with Custom Content View
body: <p>I can't seem to figure out how to display ads on my app while currently, instead of setting my content view to the layout file, I am setting my view to a custom class which draws a canvas. I have the following:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  
          MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544~3347511713");
  
          AdView mAdView = (AdView) findViewById(R.id.adView);
          AdRequest adRequest = new AdRequest.Builder().build();
          mAdView.loadAd(adRequest);
  
          setContentView(new GamePanel(this));
      }
  </code></pre>
  
  <p>Of course I get a null pointer error. Of course this happens because I edit the AdViews before setting the content view, but even if I switch the order it doesn't work (even without an error I am worried it will just be hidden behind my canvas). Here is my <code>GamePanel</code> class.</p>
  
  <pre><code>public class GamePanel extends SurfaceView implements SurfaceHolder.Callback {
      public GamePanel(Context context) {
          super(context);
  
          getHolder().addCallback(this);
  
          thread = new MainThread(getHolder(), this);
          thread.run();
  
          setFocusable(true);
       }
       @Override
       public void draw(Canvas canvas) {
          super.draw(canvas);
          //draw a bunch of gameobjects...
       }
       public void update() {
           //update objects
       }
       //required methods...
  }
  </code></pre>
  
  <p>And essentially in the main thread I just loop through frame cycles, call the <code>GamePanel</code>'s <code>update()</code> and <code>draw(Canvas canvas)</code> methods and then use <code>surfaceHolder.unlockCanvasAndPost(canvas);</code> (where <code>surfaceHolder</code> is the one corresponding to the GamePanel) to draw the canvas to the screen. I don't use Android Studio's view structure, so I don't know how to implement an Ad View.</p>