0

i have created a game(surfaceview) and i am trying to implement admob wherein it must be fixed at the bottom.. i have successfully implemented the admob and shows it properly but what i did is i call it in main activity.

AdView adView = (AdView)findViewById(R.id.adView);
        adView.loadAd(new AdRequest());

and i have this on all layouts

 <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/unit_id"
        ads:loadAdOnCreate="true"
         />

what i need to do is show the admob but it will not be affected even if the screen switches it is fixed in the bottom part of the screen. i have searched for some thing like this but i have no success. i hope someone can help or even explain on how i can achieve this.

P.S. its like 1 banner for all activities.

NoobMe
  • 544
  • 2
  • 6
  • 26
  • I don't think you can use 1 banner for all activities, however can you put your game code in fragments and put the banner in its own fragment? – Morrison Chang Sep 17 '13 at 04:41

3 Answers3

0

Use Only Xml Coding without Java Code

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="App ID"`enter code here`
        ads:testDevices="25" 
        ads:loadAdOnCreate="true" />
</RelativeLayout>
Raptor
  • 53,206
  • 45
  • 230
  • 366
Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
  • still the same whenever i go to a certain activity the ads is refreshing.. i want it to be like its separated from the activity – NoobMe Sep 17 '13 at 03:57
0

Can you wrap the whole screen in a relative layout? You can then align the banner to the parent's bottom. You other items should be declared with layout_above to keep them above the banner. The easiest way is to wrap them in another layout.

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/adView" >

       ... your other items can go here

    </RelativeLayout>    

    <com.google.ads.AdView
        android:id="@id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="App ID"`enter code here`
        ads:testDevices="25" 
        ads:loadAdOnCreate="true" />
</RelativeLayout>
Szymon
  • 42,577
  • 16
  • 96
  • 114
  • do i have to implement that on all layouts? and when i switch activity it stays at the bottom? i mean the ad is still the same it will not change nor refresh? – NoobMe Sep 17 '13 at 04:23
  • I'm not sure what's the internals of AdView but your activity will be destroyed, e.g. when the screen orientation changes so probably AdView will be recreated too. You can't control it anyway. – Szymon Sep 17 '13 at 04:31
0

I think it will be difficult (or impossible) to have just a single unique banner span multiple Activities. The ActivityGroup group class may have allowed this kind of thing, but it was never popular and anyway has been deprecated for a while.

Meantime there remains plenty of demand for the UX motif of switching between major views within the confines of one screen. But the mechanism has been reworked to use Fragments. If you can make your SurfaceView stuff work within a Fragment, then that might be your best bet. A layout might look something like this:

<LinearLayout>
 <Fragment>
 <AdView>
<LinearLayout>

When I did this kind of thing recently, I just put the AdMob code at the bottom of every Activity, and let it reload a fresh ad with every push. There has been no scolding from the Google side regarding too-frequent ad requests, and I am getting plenty of clicks.

Good luck!

QED
  • 9,803
  • 7
  • 50
  • 87
  • so there's really no other solution to this? you think this one will not work? http://stackoverflow.com/questions/9629230/how-do-i-make-banners-ads-admob-common-for-all-my-activities – NoobMe Sep 17 '13 at 05:34
  • ok i have tried implementing the link that i posted.. but its the same to what i am doing.. the include.~ i think this will be the next thing that i will be doing~ – NoobMe Sep 17 '13 at 06:12
  • i have changed all to fragment but i have one more little problem.. everytime my activity changes the banner still refreshes but it is now in a single xml layout. you have any ideas on how i can implement admob without it being affected by fragment activities? – NoobMe Sep 19 '13 at 08:45
  • The only thing that you can do, I think, is to maintain your AdView object as application state. You can perhaps in your `class MyApp extends Application`. Then at runtime when your Activity comes up, add the AdView into your layout. This might work, but I haven't tried it. – QED Sep 19 '13 at 18:23