Visibility.GONE and Refresh

228 views
Skip to first unread message

Peter

unread,
Aug 30, 2011, 8:40:14 PM8/30/11
to Google AdMob Ads Developers
Hi,

I am using AdWhirl with Admob and Millennial my eCPM is going lower
and lower because while the ad is hidden it is refreshing in the
background. I'm using handler to hide show ads during different Views
in my app.

How can I stop AdWhirl making ad request I am currently using an xml
implementation below. Even though the visibility is gone it still
makes ad requests.

<com.adwhirl.AdWhirlLayout
android:id="@+id/adwhirl_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />

Peter

unread,
Sep 2, 2011, 12:56:53 AM9/2/11
to Google AdMob Ads Developers

Peter

unread,
Sep 2, 2011, 5:27:47 AM9/2/11
to Google AdMob Ads Developers
Anyone that could provide help on this it would be greatly
appreciated!

Jim

unread,
Sep 2, 2011, 1:09:23 PM9/2/11
to Google AdMob Ads Developers
Additional code would help (XML and java). Can you give the "short
version" of what is happening with the rest of the code? You mention
an ad handler, so seeing that would help, too.

-Jim

Peter

unread,
Sep 2, 2011, 1:24:22 PM9/2/11
to google-adm...@googlegroups.com
Hi Jim,

Mobile at the moment. Adwhirl only requires the class call in xml and the adwhirl key in the manifest plus all the provider sdk on the build path. Everything is working fine ads load and rotate between millennial and admob. All that Im trying to figurr out is how to stop adwhirl loading ads when visibility.gone is invoked then re load when visibility.visible is invoked. AdWhirl documentation is minimal does not discuss anything regrading this.

Best Regards

Jason

Eric Leichtenschlag

unread,
Sep 2, 2011, 4:52:25 PM9/2/11
to google-adm...@googlegroups.com
Hey Jason,

Currently AdWhirl only stops refreshing when the window containing the AdWhirlLayout is not visible.  This may be worth implementing to a future version of AdWhirl, but to get this feature now you would have to add this functionality and build the source code yourself.

One way of doing this would be to check the visibility in rotateAd() and call rotateThreadedDelayed() and returning before making an ad request.  This has a little overhead though where you are still executing a couple lines of code every refresh, but at least you aren't making an ad request.  The full solution would be to pause the refresh when a view becomes invisible and start up the refresh again when the view becomes visible again, but this implementation would take longer to bake in.

Cheers,
Eric, AdMob SDK Support

Jason

unread,
Sep 2, 2011, 4:59:08 PM9/2/11
to Google AdMob Ads Developers
Hi Eric,

Thanks for the heads up trying to get my head around the logic could
you point me in the right.direction?

On Sep 3, 6:52 am, Eric Leichtenschlag <eleichtens...@google.com>
wrote:

Eric Leichtenschlag

unread,
Sep 2, 2011, 5:51:59 PM9/2/11
to google-adm...@googlegroups.com
In AdWhirlLayout.java (http://code.google.com/p/adwhirl/source/browse/src/com/adwhirl/AdWhirlLayout.java?repo=sdk-android#236), the rotateThreadedDelayed function fires a runnable which will eventually call rotateAd().  In rotateAd(), there is a check if the window is visible before requesting a new ad.  The quick solution would be to also check for the AdWhirlLayout's visibility here, and simply return if not visible (thereby skipping the ad request), but calling rotateThreadedDelayed() so that the scheduler will call rotateAd() during the next refresh.

The better solution would be stopping the scheduler altogether, and starting it again when the AdWhirlLayout becomes visible again, similar to what the onWindowVisibilityChanged() logic does.  Basically, you would be implementing onWindowVisibilityChanged() logic in a callback onVisibilityChanged() for when the AdWhirlLayout changes visibility.

Hope this helps.

Jason

unread,
Sep 2, 2011, 6:04:11 PM9/2/11
to Google AdMob Ads Developers
Hi Eric,

Yes that does help but must I create a new jar and modify the AdWhirl
source or can I accomplish this from within my code? Sorry for the
newb questions.

On Sep 3, 7:51 am, Eric Leichtenschlag htens...@google.com> wrote:
> I<http://code.google.com/p/adwhirl/source/browse/src/com/adwhirl/AdWhir...>n
> AdWhirlLayout.java (http://code.google.com/p/adwhirl/can source/browse/src/com/adwhirl/AdWhir...),

Eric Leichtenschlag

unread,
Sep 2, 2011, 6:14:12 PM9/2/11
to google-adm...@googlegroups.com
Unfortunately this requires modifying the AdWhirl source and then building a new jar for your application.

Jason

unread,
Sep 2, 2011, 6:25:05 PM9/2/11
to Google AdMob Ads Developers
Kinda weird Google allowing customers to loose ad impressions for lack
of a built in solution.

On Sep 3, 8:14 am, Eric Leichtenschlag <eleichtens...@google.com>
wrote:
> Unfortunately this requires modifying the AdWhirl source and then building a
> new jar for your applicatio
>

Jason

unread,
Sep 2, 2011, 11:44:42 PM9/2/11
to google-adm...@googlegroups.com
Hi Eric,

Got this working simply by doing this in AdWhirlLayout.java of the AdWhirl Android SDK and exporting it as a jar.

private void rotateAd() {
    if (!this.hasWindow) {
      this.isScheduled = false;
      return;
    }
    
    if (this.getVisibility() == View.GONE) {
     this.rotateThreadedDelayed();
     Log.e("AWLayout", "View.GONE");
     return;  
    }

    Log.e("AWLayout", "View.VISIBLE");

    Log.i(AdWhirlUtil.ADWHIRL, "Rotating Ad");
    nextRation = adWhirlManager.getRation();

    handler.post(new HandleAdRunnable(this));
  }

 public void run() {
      AdWhirlLayout adWhirlLayout = adWhirlLayoutReference.get();
      if (adWhirlLayout != null) {
        Activity activity = adWhirlLayout.activityReference.get();
        if (activity == null) {
          return;
        }

        if (adWhirlLayout.adWhirlManager == null) {
          adWhirlLayout.adWhirlManager = new AdWhirlManager(
              new WeakReference<Context>(activity.getApplicationContext()),
              keyAdWhirl);
        }

        if (!adWhirlLayout.hasWindow) {
          adWhirlLayout.isScheduled = false;
          return;
        }
        
        if (adWhirlLayout.getVisibility() == View.GONE) {
            adWhirlLayout.rotateThreadedDelayed();
            Log.e("AWLayout", "View.GONE");
            return;  
        }
        
        Log.e("AWLayout", "View.VISIBLE");
                
        adWhirlLayout.adWhirlManager.fetchConfig();
        adWhirlLayout.extra = adWhirlLayout.adWhirlManager.getExtra();

        if (adWhirlLayout.extra == null) {
          adWhirlLayout.scheduler.schedule(this, 30, TimeUnit.SECONDS);
        } else {
          adWhirlLayout.rotateAd();
        }
      }
    }
  }

Reply all
Reply to author
Forward
0 new messages