Android, AdMob: updating AdMob ads reduces frame rate

I am developing a game and it is going well. However, I have a problem updating AdMob ads. Every time an ad is updated or draws another aspect of the ad, my frame rate drops and almost makes the game unplayable. Here is what I have to download ads ...

ad = new AdView(this, AdSize.BANNER, "..."); AdRequest adRequest = new AdRequest(); adRequest.addTestDevice("..."); adRequest.addTestDevice("..."); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); lp.addRule(RelativeLayout.CENTER_HORIZONTAL); ad.setLayoutParams(lp); RelativeLayout layout = new RelativeLayout(this); layout.addView(renderView); layout.addView(ad); ad.loadAd(new AdRequest()); setContentView(layout); 

My solution for rendering an ad on top of SurfaceView was to simply add it to RelativeLayout and add both SurfaceView and AdView . All this works fine and dandy, but every time the ad is updated (user interface or new ad request), it wraps the user interface flow, which in turn slows down the rendering flow.

Is there a way by which I can do all this together well so that all the work done by AdView is done separately from the main thread? I'm not too sure about dynamically updating the current layout from another thread.

Thanks for the help.

+7
source share
2 answers

I also had this problem. I found that this was caused by Google ads that were waiting for them to change, rather than static Admob ads that didn't expect at all. There is a setting in the settings of your admob application to control the use of Google ads ... try disabling it to see if this has changed.

+8
source

Sorry to resurrect this question, but I managed to deal with the same problem and found out that turning LAYER_TYPE_SOFTWARE into an AdView internal WebView made it smoother.

I confirmed that this works on my side with version 8.4.0 running on Android 5.1, although it is possible that this workaround will benefit more devices with stronger processors.

In my onResume activity I have

 /* * The AdView attaches it internal WebView only once it * has been loaded, so we need to wait until that happens. */ adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { runOnWebView(mAdView, new WebViewAction() { @Override public void run(WebView view) { // the most important part is here view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } }); } }); 

using the runOnWebView method and the WebViewAction interface defined as

 /** * Recursively searches for a WebView instance located in * the hierarchy of view and invokes the callback method on * action with the found instance. */ private void runOnWebView(View view, WebViewAction action) { if (view instanceof WebView) { action.run((WebView) view); return; } if (view instanceof ViewGroup) { final ViewGroup parent = (ViewGroup) view; for (int i = 0; i < parent.getChildCount(); i++) { runOnWebView(parent.getChildAt(i), action); } } } private interface WebViewAction { void run(WebView view); } 
+3
source

All Articles