MREC is 300x250 banner. This type can be useful if the application has a large free area for placing a banner in the interface.

1. Display MREC

Add com.appodeal.ads.MrecView to your layout file:

<com.appodeal.ads.MrecView
	android:id="@+id/appodealMrecView"
	android:layout_width="300dp"
	android:layout_height="250dp"
	android:layout_centerInParent="true"
	android:visibility="gone" />
Set view id before the SDK initialization:
Appodeal.setMrecViewId(R.id.appodealMrecView);
Now you can show the banner in the specified view:
Appodeal.show(this, Appodeal.MREC);

SDK can't show ads without a network connection!

Appodeal.show() returns a boolean value indicating whether the show method call was passed to the appropriate SDK. 

2. Display MREC in programmatically created view

Create banner view:

Appodeal.getMrecView(this);
Add view to your layout and then show the banner in it:
Appodeal.show(this, Appodeal.MREC);

3. Check if MREC is loaded

Appodeal.isLoaded(Appodeal.MREC);

4. Use MREC callbacks

Appodeal.setMrecCallbacks(new MrecCallbacks() {
  @Override
  public void onMrecLoaded(boolean isPrecache) {
    // Called when MREC is loaded
  }
  @Override
  public void onMrecFailedToLoad() {
    // Called when MREC failed to load
  }
  @Override
  public void onMrecShown() {
    // Called when MREC is shown
  }
  @Override
  public void onMrecShowFailed() {
    // Called when MREC show failed
  }
  @Override
  public void onMrecClicked() {
    // Called when MREC is clicked
  }
  @Override
  public void onMrecExpired() {
    // Called when MREC is expired
  }
});

All callbacks are called on the main thread.

5. Activity "Paused" state handling

We’ll automatically handle pause and resume state for already displayed MRECs on Activity on which they were displayed, however, we don’t restore displayed MRECs after Activity recreation (e.g. - orientation changes) and we don’t show MRECs in newly created Activities.
For display ads on newly created Activity just call Appodea.show() method if required.

@Override
public void onResume() {
    super.onResume();
    Appodeal.show(this, Appodeal.MREC);
}

This behavior can be changed by calling Appodeal.setSharedAdsInstanceAcrossActivities(true)
(See more: Enable Shared View Ads Instance Across Activities Logic)

6. Hide MREC

Appodeal.hide(this, Appodeal.MREC);

7. Destroy shown MREC

If you want to hide the MREC from all activities and clear the memory, call the code below:

Appodeal.destroy(Appodeal.MREC);

8. Cache MREC manually

To disable automatic caching for MREC, use the code below before the SDK initialization:

Appodeal.setAutoCache(Appodeal.MREC, false);
To cache 300*250 banners, use:
Appodeal.cache(this, Appodeal.MREC);
Read more on manual caching in our FAQ.

9. Check if MREC was initialized

To check if MREC was initialized, you can use the method:

Appodeal.isInitialized(activity, Appodeal.MREC);
Returns true, if the MREC was initialized.

10. Check if autocache is enabled for MREC

To check if autocache is enabled for MREC, you can use the method:

Appodeal.isAutoCacheEnabled(activity, Appodeal.MREC);
Returns true, if autocache is enabled for MREC.

11. Get predicted eCPM for MREC

To get the predicted eCPM from the next block in the caching queue, use the method:

Appodeal.getPredictedEcpm(Appodeal.MREC);

This method is reasonable to use if manual caching of ads is enabled.

12. Enable Shared View Ads Instance Across Activities Logic

Starting from SDK 2.8.1 Appodeal SDK binds the Banner/MREC to the Activity which was passed to the Appodeal.show method.

To make it easier for you to manage View ads display logic across all Activities we added a new method in Appodeal class:

Appodeal.setSharedAdsInstanceAcrossActivities(boolean sharedAdsInstanceAcrossActivities); // Default - false

  • When this method is used with the true parameter, the SDK will show AdView on all new activities without calling additional code from your side.
  • If you want to control the display yourself, you can call the method with the false parameter.

In this case, this parameter is false, be careful with changing orientation or moving to a new activity, the banner/MREC will not be shown automatically, since it was bound to the previous activity.
If you want to hide the banner/MREC, you need to call the Appodeal.hide() method with the parameters of the activity to which the banner/MREC was bound.

You can also check the current state of this logic. By default value is false:

Appodeal.isSharedAdsInstanceAcrossActivities();