1

I'm trying to integrate AdWhirl and AdMob in my Android Application and I have some question:

  1. I have many activities and I want put advertisement in most of them. In which activity should I put the following code?

    //***ADWHIRL CODE // These are density-independent pixel units, as defined in // http://developer.android.com/guide/practices/screens_support.html int width = 320; int height = 52;

    DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    float density = displayMetrics.density;
    
    width = (int) (width * density);
    height = (int) (height * density);
    
    // Optional, will fetch new config if necessary after five minutes.
    AdWhirlManager.setConfigExpireTimeout(1000 * 60 * 5);
    
    // References AdWhirlLayout defined in the layout XML.
    AdWhirlLayout adWhirlLayout = (AdWhirlLayout) findViewById(R.id.adwhirl_layout);
    adWhirlLayout.setAdWhirlInterface(this);
    adWhirlLayout.setMaxWidth(width);
    adWhirlLayout.setMaxHeight(height);
    //*******ADWHIRL CODE END
    

I already put also this code in AndroidManifest:

<!-- AdWhirl Key -->
    <meta-data android:value="7e*********************5a6"
        android:name="ADWHIRL_KEY" />

    <!-- AdMob integration -->
    <activity android:name="com.google.ads.AdActivity"
        android:configChanges="orientation|keyboard|keyboardHidden" />
  1. Is it possible show the ads always in the foreground, in a indipendent way from the height of the content?

Does anyone have any advice? Any help is appreciated. Sorry for my English.

user970644
  • 13
  • 4

1 Answers1

1

While the code at the top is nice to make sure your AdWhirlLayout doesn't extend upon the dimensions of the screen, you shouldn't need to include that at all. You could get away with wrapping the content of the AdWhirlLayout you define in XML. You will need to have an AdWhirlLayout in each activity that you want to display ads in, however.

To show your ads in the same place regardless of content, consider using a RelativeLayout and using the android:layout_alignParentBottom="true" property in your AdWhirlLayout to assign the ad to the bottom of the screen, for example.

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
  • Thanks for you help Eric Leichtenschlag! I tried your solution and the ad is shown at the bottom of the screen. I put here my code for someone else with the same problem. ` ` – user970644 Sep 30 '11 at 08:45
  • For handle many activities with the same code, I put the creation of the ad (the first code I written in the question) in one activity that is extends from the others. The problem is still the same, for every activity that is created, it is reload a new ad. Do you have some advice? – user970644 Sep 30 '11 at 08:51
  • I"m not sure I understand the question. Don't you want a new ad when you go to a new activity? – Eric Leichtenschlag Sep 30 '11 at 16:01
  • No, I don't. I would like load the same advertising for all my activities (until it will be refreshed from AdMob) . I'm trying to explain the problem (sorry again for my English). For example: I have activity A with some constants, and activities B,C and D. Activity B, C and D extend A. I want to show ads in activities B,C and D. I would like put most of the code for handle ads in activity A. In this way, while the user navigates between activities B, C or D, the advertise does not disappear (for loading reasons). Is it possible? – user970644 Sep 30 '11 at 17:46
  • So if I understand correctly, you want to retain the AdWhirlView accross multiple screens. There is no really no easy way to do that. Android only released [fragments](http://developer.android.com/guide/topics/fundamentals/fragments.html) on Honeycomb, so this type of thing has more of a tablet use case. The only reasonable way to do something like this would be workarounds where you stay in the same activity and try to alter the screen layout, but leaving the AdWhirlView, but I doubt this will be reasonable for you. I think it is best practice to just put an AdWhirlView in each activity. – Eric Leichtenschlag Sep 30 '11 at 20:48
  • You understood the problem perfectly. It is not possible for me stay in the same activity and try to alter the screen layout , but leaving the AdWhirlView, because I have more than 20 activities. I prefer not use fragments (I'm developing for Eclair and Froyo), so I will put an AdWhirlView in each activity, as you suggest. Thankyou for you time, best regards. – user970644 Oct 03 '11 at 08:11