I have extended the GLSurfaceView and implemented my own GLSurfaceView.Renderer to create my first relatively simple 2D OpenGLES game for android.
I have been testing my game using the following code on the activities onCreate method which sets the surface view as the content view, from which I have obtained a constant 60fps.
60fps activity :
mGLView = new OpenGLTest1SurfaceView(this);
setContentView(mGLView);
However now I have moved to an XML layout so I can place an admob overlay in the bottom right corner of the screen,
admob xml :
<Frame Layout...
<...OpenGLTest1SurfaceView...
<com.google.ads.adView...
admob activity :
setContentView(R.layout.main);
Now I the application fluctuates between 43fps and 60fps at seemingly random intervals. I have looked at the LogCat and the GC is not running excessively (once every 20seconds or so).
- Should I have expected a lower frame rate when moving my surface view into an XML layout?
- Is there an alternative method for showing admob adverts without using an XML layout?
- Is there anything I could do to identify why my applications FPS lowers at particular times?
Any help would be greatly appreciated because I would like to be able to monetize my OpenGL applications in the near future.
I read about something similar awhile ago, the solution was to put the overlay in a separate window, on top of the glsurfaceview.
I don't remember where, but I defiantly read some place in android that when you are updating a view, such as your OpenGLTest1SurfaceView, screen invalidation is fired on the rect that your view is taking so if you place the admobe above it your fps will fall down. If you place the admobe beside it you will be fine.
GLSurfaceView being a SurfaceView has a little bit different way of being represented in a window.
First step you need to draw AdMobView in a separate window (layer) on top of your main window. Here is an example of how you do it:
"yourAwesomeView" here is a layout containing adView. Beware you have to properly configure flags for window to let your touches slip to background window. Also you're resposible for removing this window.
Another advice I may have is to try disabling default background in your theme since your GLSurfaceView is on top of it, you don't want extra draws behind it.
in your theme add
Hope this helps.
To answer one of those points, you can definitely create and AdMob ad and put it into your view hierarchy programmatically, you probably just need to give it a gravity of "
bottom
" or something so that it stays at the bottom of the FrameLayout.