public class MediaActivity extends RequestPermissionActivity implements PrerollAdListener { private static final String TAG = "MediaActivity"; private RelativeLayout mAdLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_media); mAdLayout = (RelativeLayout) findViewById(R.id.adLayout); // Permission handling code for Android 6.0 and Above super.requestAppPermissions(mPermissions, R.string.runtime_permissions, REQUEST_PERMISSIONS); } @Override public void onPermissionsGranted(int requestCode) { showPrerollAd(); } private void showPrerollAd() { preRollVideoAd = PreRollVideoAd.getInstance(this); String contentVideo = "http://cdn.vdopia.com/files/happy.mp4"; ViewGroup parent = (ViewGroup) preRollVideoAd.getParent(); if (parent != null) { parent.removeAllViews(); } mAdLayout.addView(preRollVideoAd); preRollVideoAd.setPrerollAdListener(this); preRollVideoAd.showAd(); } @Override public void onPrerollAdLoaded(View prerollAd) { Log.d(TAG, "PreRoll Video Ad onPrerollAdLoaded"); } @Override public void onPrerollAdFailed(View prerollAd, LVDOAdRequest.LVDOErrorCode errorCode) { Log.d(TAG, "PreRoll Video Ad onPrerollAdFailed"); } @Override public void onPrerollAdClicked(View prerollAd) { Log.d(TAG, "PreRoll Video Ad onPrerollAdClicked"); } @Override public void onPrerollAdCompleted(View prerollAd) { Log.d(TAG, "PreRoll Video Ad onPrerollAdCompleted"); } @Override public void onPrepareMainContent(MediaPlayer player) { Log.d(TAG, "PreRoll Video onPrepareMainContent"); } @Override public void onErrorMainContent(MediaPlayer player, int code) { Log.d(TAG, "PreRoll Video onErrorMainContent : " + code); setContentVisibility(); } @Override public void onCompleteMainContent(MediaPlayer player) { Log.d(TAG, "PreRoll Video onCompleteMainContent"); setContentVisibility(); } private void setContentVisibility() { MediaActivity.this.finish(); } }