Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:10:15+00:00 2026-06-13T20:10:15+00:00

I have an AndEngine game wich subclasses from public class BaseActivity extends SimpleBaseGameActivity {

  • 0

I have an AndEngine game wich subclasses from

public class BaseActivity extends SimpleBaseGameActivity {

}

The game works fine, now when I try to add Admob view to it, I learned from posters on SO to override the onSetContentView() method.

Which I do like this:

@Override
protected void onSetContentView() {

    //Creating the parent frame layout:
    final FrameLayout frameLayout = new FrameLayout(this);

    //Creating its layout params, making it fill the screen.
    final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);

    //Creating the banner view.
    AdView adView = new AdView(this, AdSize.BANNER, AdMobPubId);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());

    // set the layout properties
    final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL);


    // Creating AndEngine's view - Reference made
    this.mRenderSurfaceView = new RenderSurfaceView(this);
    mRenderSurfaceView.setRenderer(mEngine, null);


    //createSurfaceViewLayoutParams is an AndEngine method for creating the params for its view.
    final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

    //Adding the views to the frame layout.
    frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
    frameLayout.addView(adView, adViewLayoutParams);

    //Setting content view
    this.setContentView(frameLayout, frameLayoutLayoutParams);
}

The ad gets loaded, but the screen is black. My game is gone.
The screen still registers touches (as I see in the debugger)

How come the engine is not shown in the lower view?!?!

EDIT: Finally got it working

used this code and suddenly it worked, not sure why it didn’t before

@Override
    protected void onSetContentView() {
        this.mRenderSurfaceView = new RenderSurfaceView(this);
        this.mRenderSurfaceView.setRenderer(this.mEngine, this);
        final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());

        //Creating the banner view.
        AdView adView = new AdView(this, AdSize.BANNER, AdMobPubId);
        adView.loadAd(new AdRequest());
        final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_HORIZONTAL);


        final FrameLayout frameLayout = new FrameLayout(this);
        final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);

        frameLayout.addView(this.mRenderSurfaceView,surfaceViewLayoutParams);
        frameLayout.addView(adView,adViewLayoutParams);
        this.setContentView(frameLayout, frameLayoutLayoutParams);

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:10:16+00:00Added an answer on June 13, 2026 at 8:10 pm

    It doesn’t work because you change the layout after it has been inflated. You can’t add views after you already called setContentView and inflated the layout.

    All you have to do is to create the AdView earlier and add it to the layout before AndEngine calls setContentView. You can see an example of doing so here.

    I’m using FrameLayout in this example, it’s taken from my game where FrameLayout works the best. Your onSetContentView method will be simpler – all you have to do is to instatiate the RenderSurfaceView object and the AdView object, then add them to a new LinearLayout and call setContentView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code like this: public class SnowFallService extends BaseLiveWallpaperService implements IOnAreaTouchListener{ // ===========================================================
I'm using AndEngine/Box2d to develop a game. I have a ball that bounces around
I have developed simple 2D games with AndEngine but now I want to make
I'm developing a physics game using AndEngine with box2d physics engine. I have a
I have developed a game using andengine with PORTRAIT_FIXED ScreenOrientation . This is a
I have developed a game using andengine I am facing a problem when using
I have written a simple game, with AndEngine. In this game I want to
I'm developing a game for Android using andEngine. I have to change sprite images
I am using java + AndEngine in my game. During the game i have
I have a method in engine i'm using (andengine) : public final void setText(String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.