# AppOpen (Google)

App open ads are a special fullscreen ad format (created by Google) intended for publishers wishing to monetize their app loading screens (“splash screens”). App open ads can be closed at any time, and are designed to be shown when your users bring your app to the foreground.

### Create Placement <a href="#create-placement" id="create-placement"></a>

You need to create the AppOpen placement as soon as the app becomes active in the `applicationDidBecomeActive()` method in your `AppDelegate`.

To create an instance of [AppOpenAdPlacement](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-app-open-ad-placement/index.html), use the following API:

{% tabs %}
{% tab title="Java" %}

```java
private AppOpenAdPlacement placement = AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val placement = AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>")
```

{% endtab %}
{% endtabs %}

### Listen to Callbacks (Optional) <a href="#listen-to-callbacks-optional" id="listen-to-callbacks-optional"></a>

Through the use of [AppOpenPlacementListener](https://android-sdk.aatkit.com/references/-a-a-t-kit/com.intentsoftware.addapptr/-app-open-placement-listener/index.html), you can listen to the different placement callbacks.

{% tabs %}
{% tab title="Java" %}

```java
placement.setListener(this);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
placement.listener = this
```

{% endtab %}
{% endtabs %}

### Request Ad

After creating the placement you need to start placement auto-reloading to get an ad as soon as possible.

{% tabs %}
{% tab title="Java" %}

```java
@Override
protected void onResume() {
    super.onResume();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this);

    // Start autoreloading the placement.
    placement.startAutoReload();
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
override fun onResume() {
    super.onResume()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this)

    // Start autoreloading the placement.
    placement?.startAutoReload()
}
```

{% endtab %}
{% endtabs %}

### Request Ad (In Loading Screen)

App Open Placement is meant to monetize your App Loading screen, so the most proper place to display the Ad is in your own Loading Activity, so while the user is waiting for your App to be ready to use. If AATKit has successfully obtained an Ad you should display it before sending the user to the main content. To do so you will need your `LoadingActivity` to implement the `AppOpenPlacementLitener` interface:

{% tabs %}
{% tab title="Java" %}

```java
private AppOpenAdPlacement placement = AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>");

@Override
protected void onResume() {
    super.onResume();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this);

    // Set placement listener to listen to the callbacks
    placement.setListener(this);
    // Start autoreloading the placement.
    placement.startAutoReload();
}

@Override
protected void onPause() {
    // [IMPORTANT] Stop placement autoreload
    placement.stopAutoReload();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityPause(this);
    super.onPause();
}

// AppOpenPlacementListener
@Override
public void onPauseForAd(@NonNull Placement placement) {
    // Ad has been displayed on the screen
}

@Override
public void onResumeAfterAd(@NonNull Placement placement) {
    // Back to the app
}

@Override
public void onHaveAd(@NonNull Placement placement) {
    // The placement has loaded a new ad
}

@Override
public void onNoAd(@NonNull Placement placement) {
    // The placement could not load a new ad
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
private val placement = createAppOpenAdPlacement("<PLACEMENT_NAME>")

override fun onResume() {
    super.onResume()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this)

    // Set placement listener to listen to the callbacks
    placement?.listener = this
    // Start autoreloading the placement.
    placement?.startAutoReload()
}

override fun onPause() {
    // [IMPORTANT] Stop placement autoreload
    placement?.stopAutoReload()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityPause(this)
    super.onPause()
}

// AppOpenPlacementListener
override fun onPauseForAd(placement: Placement) {
    // Ad has been displayed on the screen
}

override fun onResumeAfterAd(placement: Placement) {
    // Back to the app
}

override fun onHaveAd(placement: Placement) {
    // The placement has loaded a new ad
}

override fun onNoAd(placement: Placement) {
    // The placement could not load a new ad
}
```

{% endtab %}
{% endtabs %}

After the user closes the Ad you should send the user to your app's main content, you will get notified when the fullscreen ad is closed in `onResumeAfterAd` listener method.

### Display Ad

You should display that ad at the start of the app session by calling `show()` method. If the AppOpen placement has a ready ad, It will present it.

{% tabs %}
{% tab title="Java" %}

```java
placement.show();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
placement.show()
```

{% endtab %}
{% endtabs %}

### Complete Code Example

{% tabs %}
{% tab title="Java" %}

```java
private AppOpenAdPlacement placement = AATKit.createAppOpenAdPlacement("<PLACEMENT_NAME>");

@Override
protected void onResume() {
    super.onResume();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this);

    // Start autoreloading the placement.
    placement.startAutoReload();
    // Display loaded ad (if available)
    placement.show();
}

@Override
protected void onPause() {
    // [IMPORTANT] Stop placement autoreload
    placement.stopAutoReload();
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityPause(this);
    super.onPause();
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
private val placement = createAppOpenAdPlacement("<PLACEMENT_NAME>")

override fun onResume() {
    super.onResume()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityResume(this)

    // Start autoreloading the placement.
    placement?.startAutoReload()
    // Display loaded ad (if available)
    placement?.show()
}

override fun onPause() {
    // [IMPORTANT] Stop placement autoreload
    placement?.stopAutoReload()
    // [IMPORTANT] Notify AATKit about activity lifecycle
    AATKit.onActivityPause(this)
    super.onPause()
}
```

{% endtab %}
{% endtabs %}

### Loading Screen

The above code example assumes that you only show app open ads when users foreground your app after it is suspended in memory. So, if the user launches the app either for the first time since booting or after killing the application, the app will never have a ready ad.

In this case, it’s preferred to use a loading screen (that might be used to load your assets) and only show the ad from the loading screen (Only if the ad is ready and the loading screen is still active) to avoid surprising the user with an ad while using your app.

If you have a loading screen under the app open ad, and your loading screen completes loading before the ad is dismissed, you may want to dismiss your loading screen in the `resumeAfterAd()` callback of the `AppOpenPlacementListener`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://aatkit.gitbook.io/android-integration/formats/appopen-google.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
