1

I have an activity which has a surfaceview capturing whole screen. i want to put an admob ad on surfaceview. I found this link but it does not work. Any idea ?

4
  • The link works fine here. Maybe you mean the provided code doesn't work? In this case, please post your code so we can have a look at it. Commented May 29, 2011 at 21:03
  • I tried the code at that page. It did not work. Commented May 30, 2011 at 5:24
  • It did not work helps nobody. Post the code you tryed and the Error or Exception-Message you recieved Commented May 30, 2011 at 11:45
  • have tried it and it doesnt work. Actually there are no errors or logs. dont know what to do next? @Kamil: were you able to get this resolved? thanks Commented Aug 12, 2011 at 10:17

1 Answer 1

9

In your activity's onCreate:

// Add admob ads. admobView = new AdView(this, AdSize.BANNER, "YOUR_UNIT_ID"); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); admobView.setLayoutParams(lp); RelativeLayout layout = new RelativeLayout(this); layout.addView(surfaceView); layout.addView(admobView); admobView.loadAd(new AdRequest()); setContentView(layout); 

IN the example above, "surfaceView" is your surfaceView instance, that you should instantiate like you do today. Don't forget to call admobView.destroy() in your activity's onDestroy.

Sign up to request clarification or add additional context in comments.

6 Comments

Do you mean admobView.destroyDrawingCache()?
your OnDestroy should include: if (admobView != null) { admobView.destroy(); }
For me (android 2.1) the admobView.destroy(); deas not exist, insteed admobView.destroyDrawingCache(). Is it the same thing?
You should update your admob sdk to the new one. see:code.google.com/mobile/ads/download.html
Its not admob specific, but a View method. see: developer.android.com/reference/android/view/…
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.