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

  • Home
  • SEARCH
  • 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 4096306
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:01:47+00:00 2026-05-20T20:01:47+00:00

OK, I had asked a similar question before and had got an answer but

  • 0

OK, I had asked a similar question before and had got an answer but that was too general a question.

Now I’ve an app in which there are plenty of activities. Each activity has the same admob (AdView) layout being included in its layout file. Now the problem is when I go from one activity to the other after the first screen has finished loading the ad, the second activity still waits for another ad fetch cycle to happen [ie., it again sends an ad request and displays a new ad]. All I want to do is for my app to show the same instance of the ad in every activity. [Same instance meaning: I have a time interval based on which the ads must refresh, so a new ad request must be sent only when the time limit expires, not when user navigates from one activity to another.]

Is there anyway I can do this. I have tried the “Singleton” approach mentioned in the earlier solution but there are lot of complications cos everytime I do that, it says that the specified child already has a parent and a call to removeView on the parent is necessary.

Am I doing anything wrong (OR/AND) can anybody help me with some other solution??

My Singleton class is here:

public class CommonAdFooter {
static final CommonAdFooter commonAdFooter = new CommonAdFooter();
static AdView admobView;
LayoutInflater LInflater;

private CommonAdFooter() {
    LInflater = (LayoutInflater) Constants.context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    admobView = (AdView) LInflater.inflate(R.layout.ad_layout, null);
    LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    admobView.setLayoutParams(lp);
}

public static AdView getAdLayout() {
    return admobView;
}
}

and this is my layout file for the ads

<?xml version="1.0" encoding="utf-8"?>
<com.admob.android.ads.AdView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="..."
android:id="@+id/ad" android:layout_alignParentBottom="true"
android:background="#C9E3F6" android:layout_width="fill_parent"
android:layout_height="wrap_content" myapp:backgroundColor="#006699"
myapp:primaryTextColor="#C9E3F6" myapp:secondaryTextColor="#C9E3F6" />

Edit: Admob API link added.

  • 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-05-20T20:01:47+00:00Added an answer on May 20, 2026 at 8:01 pm

    I’m not sure on the exact syntax, could you link the AdMob api?

    But your getting an error because when you return the ad layout it is already attached to the previous activity. So you would need something like this:

    public static AdView getAdLayout() {

    admobView.removeParent(); // or similar see API

    return admobView;

    }

    EDIT

    Ah here we go:
    AdView JavaDoc so it herits from view and RelativeLayout great.

    Try this:

    public static AdView getAdLayout() {
         if(admobView.getParent() != null){
            admobView.detachAllViewsFromParent();
         }
        return admobView;
    }
    

    or

    public static AdView getAdLayout() {
         if(admobView.getParent() != null){
            admobView.getParent().removeView(admobView);
         }
        return admobView;
    }
    

    The answer is in the JavaDoc just a bit of trial and error

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

Sidebar

Related Questions

I am attempting to pull some information from my tnsnames file using regex. I

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.