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 ?
1 Answer
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.
6 Comments
SlowDeepCoder
Do you mean admobView.destroyDrawingCache()?
Guy
your OnDestroy should include: if (admobView != null) { admobView.destroy(); }
SlowDeepCoder
For me (android 2.1) the admobView.destroy(); deas not exist, insteed admobView.destroyDrawingCache(). Is it the same thing?
Guy
You should update your admob sdk to the new one. see:code.google.com/mobile/ads/download.html
Guy
Its not admob specific, but a View method. see: developer.android.com/reference/android/view/…
|
It did not workhelps nobody. Post the code you tryed and the Error or Exception-Message you recieved