Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class BaseActivity extends FragmentActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IronSource.init(this, AppConfig.IRONSOURCE_APP_KEY);
...
}
}
public class MainActivity extends BaseActivity {
IronSourceBannerLayout banner;
LinearLayout adContainer;
@Override
protected void onResume() {
super.onResume();
initAd();
}
private void initAd() {
if(banner==null) {
banner = IronSource.createBanner(this, ISBannerSize.BANNER);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
adContainer = findViewById(R.id.banner_container);
adContainer.addView(banner, 0, layoutParams);
}
banner.setBannerListener(new BannerListener() {
@Override
public void onBannerAdLoaded() {
Log.oneLine("Called after a banner ad has been successfully loaded");
}
@Override
public void onBannerAdLoadFailed(IronSourceError error) {
Log.oneLine("// Called after a banner has attempted to load an ad but failed.: "+error.getErrorCode()+" "+error.getErrorMessage());
runOnUiThread(() -> adContainer.removeAllViews());
}
@Override
public void onBannerAdClicked() {
Log.oneLine("// Called after a banner has been clicked.");
}
@Override
public void onBannerAdScreenPresented() {
Log.oneLine("// // Called when a banner is about to present a full screen content.");
}
@Override
public void onBannerAdScreenDismissed() {
Log.oneLine("// // Called after a full screen content has been dismissed.");
}
@Override
public void onBannerAdLeftApplication() {
Log.oneLine("// Called when a user would be taken out of the application context.");
}
});
IronSource.loadBanner(banner);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment