> For the complete documentation index, see [llms.txt](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/android-sdk/quickstart-guide/step-2.-choose-ad-format/rewarded-video-ad.md).

# Rewarded Video Ad

## If you use jar for integration, please declare `InterstitialAdActivity` to `AndroidManifest.xml`

```markup
<activity
  android:name="com.intowow.sdk.InterstitialAdActivity"
  android:configChanges="orientation|screenSize"
  android:launchMode="singleTask"
  android:screenOrientation="portrait"
  android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
```

## Initialize `RewardedVideoAd` class

```java
import com.intowow.sdk.RewardedVideoAd;

private RewardedVideoAd mRewardedVideoAd = null;
private final static String PLACEMENT_NAME = "Obtain from your Intowow account manager";

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mRewardedVideoAd = new RewardedVideoAd(mActivity);
}
```

**NOTE :**\
please make sure to pass `Activity` on to the RewardedVideoAd.

## Setup the RequestInfo

* You need to set the placement ID and the request timeout in requestInfo.

```java
RequestInfo requestInfo = new RequestInfo();
requestInfo.setPlacement(PLACEMENT_NAME);
requestInfo.setTimeout(timeout);
```

## Load ad with RequestInfo

### loadAdInstant

```java
import com.intowow.sdk.CERequestResult;

CERequsetResult result = mRewardedVideoAd.loadAdInstant(requestInfo);
 if (result.isSuccess()) {
                // TODO: Attach the Ad View
            } else {
                // You can call result.getError() to know info of loadAd fail
            }
}
```

With `loadAdInstant` , our synchronous method , You will get the result of loading ad by [CERequestResult](/crystalexpress-documentation-v3-x/android-sdk/api-reference/cerequestresult.md) directly.&#x20;

### loadAdAsync

```java
import com.intowow.sdk.CEAdRequestListener;
import com.intowow.sdk.CERewardedVideoAdListener;

mRewardedVideoAd.loadAdAsync(requestInfo, new CEAdRequestListener() {
        @Override
            public void onError(Ad ad, AdError error) {
            }

        @Override
            public void onAdLoaded(Ad ad) {
                //  Start InterstitialAdActivity for showing this ad.
                //
                mRewardedVideoAd.show();      
            }
    });
```

loadAdAsync is an asynchronous method, you can set timeout via [RequestInfo](https://intowow.gitbook.io/crystalexpress-documentation-v3-x/~/edit/drafts/-LKuFjp4PCGTgRxN52Xr/android-sdk/api-reference/requestinfo), and get the result of ad request by [CEAdRequestListener](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ceadrequestlistener.md).

## Add `CERewardedVideoAdListener` to get the result of ad request and ad event callback.

```java
import com.intowow.sdk.Ad;
import com.intowow.sdk.AdError;
import com.intowow.sdk.RewardedVideoAd;
import com.intowow.sdk.CERewardedVideoAdListener;

private RewardedVideoAd mRewardedVideoAd = null;
private final static String PLACEMENT_NAME = "Obtain from your Intowow account manager";

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  mRewardedVideoAd = new RewardedVideoAd(mActivity, PLACEMENT_NAME);

  mRewardedVideoAd.setAdListener(new CERewardedVideoAdListener() {

    @Override
    public void onAdDisplayed(Ad ad) {
    }

    @Override
    public void onAdDismissed(Ad ad) {
    }

    @Override
    public void onAdClicked(Ad ad) {
    }

    @Override
    public void onAdImpression(Ad ad) {
    }

    @Override
    public void onAdMute(Ad ad) {
    }

    @Override
    public void onAdUnmute(Ad ad) {
    }

    @Override
    public void onVideoEnd(Ad arg0) {
    }

    @Override
    public void onVideoProgress(Ad arg0, int totalDuration, int currentPosition) {
    }

    @Override
    public void onVideoStart(Ad arg0) {
    }

  });
}
```

## Release ad when the `Activity` is destroyed

```java
@Override
protected void onDestroy() {
    if(mRewardedVideoAd != null) {
        mRewardedVideoAd.destroy();
        mRewardedVideoAd = null;
    }
    ...
    ...
    super.onDestroy();
}
```

## Handle Landscape Orientation

* There are two options to handle landscape orientation.
  * Add `android:configChanges="orientation|screenSize` in `AndroidManifest.xml`.
  * If ad is displayed in landscape mode, your `Activity` will be recreated. You can have a variable to remember if you’ve requested rewardedVideoAd ad or not in `onSaveInstanceState()`. Later you can retrieve that variable in `onCreate()` and avoid requesting rewarded ad twice. See `BaseActivity.java` in sample app source code.

```java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //...

    if (savedInstanceState != null) {
        if (savedInstanceState.containsKey(KEY_HAS_REWARDED_AD)) {
            mHasRewardedAd = savedInstanceState.getBoolean(KEY_HAS_REWARDED_AD);
            savedInstanceState.remove(KEY_HAS_REWARDED_AD);
        }
    }

    if(!mHasRewardedAd) {
      //  load ad
      //
    }
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putBoolean(KEY_HAS_REWARDED_AD, mRewardedVideoAd != null);
    super.onSaveInstanceState(outState);
}

private boolean hasRequestedRewardedAd() {
    return mHasRewardedAd;
}
```

## If you want to get more information about integration, please refer to [RewardedVideoAd](/crystalexpress-documentation-v3-x/android-sdk/api-reference/ad/rewardedvideoad.md) class.
