# firebase::gma::AdView Class Reference

# firebase::gma::AdView


`#include <ad_view.h>`

Loads and displays Google Mobile Ads [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) ads.

## Summary

Each [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) object corresponds to a single GMA ad placement of a specified size. There are methods to load an ad, move it, show it and hide it, and retrieve the bounds of the ad onscreen.

[AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) objects provide information about their current state through Futures. Methods like [Initialize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a86bc67a9a5885b6d800a16d881b963b9), [LoadAd](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1ad3161b6bd86bb92718ed4e99bb146562), and [Hide](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a55c8afd7f247b437ddce2625a3ff9243) each have a corresponding [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) from which the result of the last call can be determined. The two variants of [SetPosition](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a21b9a94625287a90e59545ce52865c20) share a single result [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future), since they're essentially the same action.

For example, you could initialize, load, and show an [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) while checking the result of the previous action at each step as follows:


```c++
namespace gma = ::firebase::gma;
gma::AdView* ad_view = new gma::AdView();
ad_view->Initialize(ad_parent, "YOUR_AD_UNIT_ID", desired_ad_size)
```

<br />

Then, later:


```c++
if (ad_view->InitializeLastResult().status() ==
    ::firebase::kFutureStatusComplete &&
    ad_view->InitializeLastResult().error() ==
    firebase::gma::kAdErrorCodeNone) {
  ad_view->LoadAd(your_ad_request);
}
```

<br />

**[Deprecated.](https://developers.google.com/admob/cpp/reference/deprecated/deprecated.md.txt)** The Google Mobile Ads C++ SDK is now deprecated. Please see <https://developers.google.com/admob/cpp/reference/namespace/firebase/gma> for more information.

| ### Constructors and Destructors ||
|---|---|
| `AdView()` Creates an uninitialized [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) object. ||
| `~AdView()` ||

| ### Public types ||
|---|---|
| `Position{ kPositionUndefined = -1, kPositionTop = 0, kPositionBottom, kPositionTopLeft, kPositionTopRight, kPositionBottomLeft, kPositionBottomRight }` | enumThe possible screen positions for a [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view), configured via [SetPosition](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a21b9a94625287a90e59545ce52865c20). |

| ### Protected attributes ||
|---|---|
| `ad_listener_` | `AdListener *` Pointer to a listener for [AdListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-listener.md.txt#classfirebase_1_1gma_1_1_ad_listener) events. |
| `ad_view_bounding_box_listener_` | `AdViewBoundingBoxListener *` Pointer to a listener for [BoundingBox](https://developers.google.com/admob/cpp/reference/struct/firebase/gma/bounding-box.md.txt#structfirebase_1_1gma_1_1_bounding_box) events. |
| `paid_event_listener_` | `PaidEventListener *` Pointer to a listener for paid events. |

| ### Public functions ||
|---|---|
| `Destroy()` | `Future< void >` Cleans up and deallocates any resources used by the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view). |
| `DestroyLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Destroy](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1abba79840893cdeb855caaba505d0a3df). |
| `Hide()` | `Future< void >` Hides the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view). |
| `HideLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Hide](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a55c8afd7f247b437ddce2625a3ff9243). |
| `Initialize(AdParent parent, const char *ad_unit_id, const AdSize & size)` | `Future< void >` Initializes the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) object. |
| `InitializeLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) that has the status of the last call to [Initialize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a86bc67a9a5885b6d800a16d881b963b9). |
| `LoadAd(const AdRequest & request)` | `Future< AdResult >` Begins an asynchronous request for an ad. |
| `LoadAdLastResult() const ` | `Future< AdResult >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [LoadAd](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1ad3161b6bd86bb92718ed4e99bb146562). |
| `Pause()` | `Future< void >` Pauses the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view). |
| `PauseLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Pause](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1afa86ebdef8488a2ab2aa44b4fbb4c810). |
| `Resume()` | `Future< void >` Resumes the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) after pausing. |
| `ResumeLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Resume](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1ad0c2c8f71f542b54fa125aa559f092cd). |
| `SetAdListener(AdListener *listener)` | `void` Sets an [AdListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-listener.md.txt#classfirebase_1_1gma_1_1_ad_listener) for this ad view. |
| `SetBoundingBoxListener(AdViewBoundingBoxListener *listener)` | `void` Sets a listener to be invoked when the Ad's bounding box changes size or location. |
| `SetPaidEventListener(PaidEventListener *listener)` | `void` Sets a listener to be invoked when this ad is estimated to have earned money. |
| `SetPosition(int x, int y)` | `Future< void >` Moves the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) so that its top-left corner is located at (x, y). |
| `SetPosition(Position position)` | `Future< void >` Moves the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) so that it's located at the given predefined position. |
| `SetPositionLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to either version of [SetPosition](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a21b9a94625287a90e59545ce52865c20). |
| `Show()` | `Future< void >` Shows the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view). |
| `ShowLastResult() const ` | `Future< void >` Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Show](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a6fd6d3a4fc8c79a01fe723ccabeb350e). |
| `ad_size() const ` | `AdSize` Returns the [AdSize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-size.md.txt#classfirebase_1_1gma_1_1_ad_size) of the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view). |
| `bounding_box() const ` | `BoundingBox` Retrieves the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view)'s current onscreen size and location. |

## Public types

### Position

```c++
 Position
```
The possible screen positions for a [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view), configured via [SetPosition](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a21b9a94625287a90e59545ce52865c20).

| Properties ||
|---|---|
| `kPositionBottom` | Bottom of the screen, horizontally centered. |
| `kPositionBottomLeft` | Bottom-left corner of the screen. |
| `kPositionBottomRight` | Bottom-right corner of the screen. |
| `kPositionTop` | Top of the screen, horizontally centered. |
| `kPositionTopLeft` | Top-left corner of the screen. |
| `kPositionTopRight` | Top-right corner of the screen. |
| `kPositionUndefined` | The position isn't one of the predefined screen locations. |

## Protected attributes

### ad_listener_

```c++
AdListener * ad_listener_
```
Pointer to a listener for [AdListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-listener.md.txt#classfirebase_1_1gma_1_1_ad_listener) events.

### ad_view_bounding_box_listener_

```c++
AdViewBoundingBoxListener * ad_view_bounding_box_listener_
```
Pointer to a listener for [BoundingBox](https://developers.google.com/admob/cpp/reference/struct/firebase/gma/bounding-box.md.txt#structfirebase_1_1gma_1_1_bounding_box) events.

### paid_event_listener_

```c++
PaidEventListener * paid_event_listener_
```
Pointer to a listener for paid events.

## Public functions

### AdView

```c++
 AdView()
```
Creates an uninitialized [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) object.

[Initialize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a86bc67a9a5885b6d800a16d881b963b9) must be called before the object is used.

### Destroy

```c++
Future< void > Destroy()
```
Cleans up and deallocates any resources used by the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).

You must call this asynchronous operation before this object's destructor is invoked or risk leaking device resources.

### DestroyLastResult

```c++
Future< void > DestroyLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Destroy](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1abba79840893cdeb855caaba505d0a3df).

### Hide

```c++
Future< void > Hide()
```
Hides the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).

### HideLastResult

```c++
Future< void > HideLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Hide](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a55c8afd7f247b437ddce2625a3ff9243).

### Initialize

```c++
Future< void > Initialize(
  AdParent parent,
  const char *ad_unit_id,
  const AdSize & size
)
```
Initializes the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) object.


Details Parameters `parent` The platform-specific UI element that will host the ad. `ad_unit_id` The ad unit ID to use when requesting ads. `size` The desired ad size for the ad.

### InitializeLastResult

```c++
Future< void > InitializeLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) that has the status of the last call to [Initialize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a86bc67a9a5885b6d800a16d881b963b9).

### LoadAd

```c++
Future< AdResult > LoadAd(
  const AdRequest & request
)
```
Begins an asynchronous request for an ad.

If successful, the ad will automatically be displayed in the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).
Details Parameters `request` An [AdRequest](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-request.md.txt#classfirebase_1_1gma_1_1_ad_request) struct with information about the request to be made (such as targeting info).

### LoadAdLastResult

```c++
Future< AdResult > LoadAdLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [LoadAd](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1ad3161b6bd86bb92718ed4e99bb146562).

### Pause

```c++
Future< void > Pause()
```
Pauses the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).

Should be called whenever the C++ engine pauses or the application loses focus.

### PauseLastResult

```c++
Future< void > PauseLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Pause](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1afa86ebdef8488a2ab2aa44b4fbb4c810).

### Resume

```c++
Future< void > Resume()
```
Resumes the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) after pausing.

### ResumeLastResult

```c++
Future< void > ResumeLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Resume](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1ad0c2c8f71f542b54fa125aa559f092cd).

### SetAdListener

```c++
void SetAdListener(
  AdListener *listener
)
```
Sets an [AdListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-listener.md.txt#classfirebase_1_1gma_1_1_ad_listener) for this ad view.


Details Parameters `listener` An [AdListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-listener.md.txt#classfirebase_1_1gma_1_1_ad_listener) object which will be invoked when lifecycle events occur on this [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).

### SetBoundingBoxListener

```c++
void SetBoundingBoxListener(
  AdViewBoundingBoxListener *listener
)
```
Sets a listener to be invoked when the Ad's bounding box changes size or location.


Details Parameters `listener` A [AdViewBoundingBoxListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view-bounding-box-listener.md.txt#classfirebase_1_1gma_1_1_ad_view_bounding_box_listener) object which will be invoked when the ad changes size, shape, or position.

### SetPaidEventListener

```c++
void SetPaidEventListener(
  PaidEventListener *listener
)
```
Sets a listener to be invoked when this ad is estimated to have earned money.


Details Parameters `listener` A [PaidEventListener](https://developers.google.com/admob/cpp/reference/class/firebase/gma/paid-event-listener.md.txt#classfirebase_1_1gma_1_1_paid_event_listener) object to be invoked when a paid event occurs on the ad.

### SetPosition

```c++
Future< void > SetPosition(
  int x,
  int y
)
```
Moves the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) so that its top-left corner is located at (x, y).

Coordinates are in pixels from the top-left corner of the screen.

When built for Android, the library will not display an ad on top of or beneath an `Activity`'s status bar. If a call to SetPosition would result in an overlap, the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) is placed just below the status bar, so no overlap occurs.
Details Parameters `x` The desired horizontal coordinate. `y` The desired vertical coordinate. **Returns** a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) which will be completed when this move operation completes.

### SetPosition

```c++
Future< void > SetPosition(
  Position position
)
```
Moves the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view) so that it's located at the given predefined position.


Details Parameters `position` The predefined position to which to move the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view). **Returns** a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) which will be completed when this move operation completes.

### SetPositionLastResult

```c++
Future< void > SetPositionLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to either version of [SetPosition](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a21b9a94625287a90e59545ce52865c20).

### Show

```c++
Future< void > Show()
```
Shows the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).

### ShowLastResult

```c++
Future< void > ShowLastResult() const 
```
Returns a [Future](https://developers.google.com/admob/cpp/reference/class/firebase/future.md.txt#classfirebase_1_1_future) containing the status of the last call to [Show](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view_1a6fd6d3a4fc8c79a01fe723ccabeb350e).

### ad_size

```c++
AdSize ad_size() const 
```
Returns the [AdSize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-size.md.txt#classfirebase_1_1gma_1_1_ad_size) of the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view).


| Details ||
|---|---|
| **Returns** | An [AdSize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-size.md.txt#classfirebase_1_1gma_1_1_ad_size) object representing the size of the ad. If this view has not been initialized then the [AdSize](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-size.md.txt#classfirebase_1_1gma_1_1_ad_size) will be 0,0. |

### bounding_box

```c++
BoundingBox bounding_box() const 
```
Retrieves the [AdView](https://developers.google.com/admob/cpp/reference/class/firebase/gma/ad-view.md.txt#classfirebase_1_1gma_1_1_ad_view)'s current onscreen size and location.


| Details ||
|---|---|
| **Returns** | The current size and location. Values are in pixels, and location coordinates originate from the top-left corner of the screen. |

### \~AdView

```c++
 ~AdView()
```