Class AppOpenAd

java.lang.Object
com.codename1.ads.AppOpenAd

public class AppOpenAd extends java.lang.Object

A full screen ad shown while the application is being brought to the foreground, overlaying the launch/splash experience.

App open ads are loaded ahead of time and shown when the user returns to the app. The recommended way to use them is to let Codename One and the provider manage the foreground hook for you:

AppOpenAd ad = new AppOpenAd("ca-app-pub-xxx/yyy");
AdManager.enableAppOpenAds(ad); // loads and auto-shows on foreground

Foreground detection is performed natively by the provider (Android process lifecycle / iOS applicationDidBecomeActive), which also honours the ad's freshness window (an app open ad expires a few hours after loading).

  • Constructor Summary

    Constructors
    Constructor
    Description
    AppOpenAd(String adUnitId)
    Creates an app open ad for the given ad unit id.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Releases the resources held by this ad.
    The listener notified of this ad's lifecycle events, may be null.
    boolean
    True when an ad is loaded and ready to show().
    void
    Loads an ad with default targeting.
    void
    load(AdRequest request)
    Loads an ad using the supplied targeting metadata.
    void
    Sets the listener notified of this ad's lifecycle events.
    void
    setAutoShowOnForeground(boolean enabled)
    Enables or disables the provider managed auto-show when the app returns to the foreground.
    void
    Presents the loaded ad.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AppOpenAd

      public AppOpenAd(String adUnitId)

      Creates an app open ad for the given ad unit id.

      Parameters
      • adUnitId: the ad unit identifier from the network console
  • Method Details

    • setAutoShowOnForeground

      public void setAutoShowOnForeground(boolean enabled)

      Enables or disables the provider managed auto-show when the app returns to the foreground. Normally driven by AdManager.enableAppOpenAds(AppOpenAd).

      Parameters
      • enabled: true to auto-show on foreground
    • setAdListener

      public void setAdListener(AdListener listener)
      Sets the listener notified of this ad's lifecycle events.
    • getAdListener

      public AdListener getAdListener()
      The listener notified of this ad's lifecycle events, may be null.
    • load

      public void load()
      Loads an ad with default targeting.
    • load

      public void load(AdRequest request)

      Loads an ad using the supplied targeting metadata.

      Parameters
      • request: optional targeting metadata, may be null
    • isLoaded

      public boolean isLoaded()
      True when an ad is loaded and ready to show().
    • show

      public void show()
      Presents the loaded ad. Does nothing if no ad is loaded.
    • dispose

      public void dispose()
      Releases the resources held by this ad.