I am trying to integrate Applovin interstitial into the code whereby if if click on the 'let's start' button its supposed to show a progress dialog as it loads the interstitial. so after the user closes the interstitial or dismisses it is supposed to go to next class which is main activity. The code I'm running just gets stuck on the loading progress dialog part. how can I fix this?
here is the code
public class StartActivity extends AppCompatActivity implements MaxAdListener {
Button start_button;
ImageView splash_icon;
TextView appTitle;
private MaxAdView adView;
private MaxInterstitialAd interstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
adView= findViewById(R.id.adView);
adView.loadAd();
start_button = findViewById(R.id.start_button);
this.appTitle = findViewById(R.id.appTitle);
this.splash_icon = findViewById(R.id.splash_icon);
start_button.setOnClickListener(view -> {
final ProgressDialog pd = new ProgressDialog(StartActivity.this);
pd.setCancelable(false);
pd.setMessage("Loading...");
pd.show();
AppLovinSdk.getInstance( StartActivity.this ).setMediationProvider( "max" );
AppLovinSdk.initializeSdk( StartActivity.this, configuration -> {
// AppLovin SDK is initialized, start loading ads
});
interstitialAd = new MaxInterstitialAd( "60f71d9283f2a0a0", StartActivity.this );
interstitialAd.setListener( StartActivity.this );
// Load the first ad
interstitialAd.loadAd();
if ( interstitialAd.isReady() )
{
interstitialAd.showAd();
}
});
}
@Override
public void onAdLoaded(MaxAd ad) {
}
@Override
public void onAdDisplayed(MaxAd ad) {
}
@Override
public void onAdHidden(MaxAd ad) {
startActivity(new Intent(StartActivity.this, MainActivity.class));
StartActivity.this.finish();
}
@Override
public void onAdClicked(MaxAd ad) {
}
@Override
public void onAdLoadFailed(String adUnitId, MaxError error) {
startActivity(new Intent(StartActivity.this, MainActivity.class));
}
@Override
public void onAdDisplayFailed(MaxAd ad, MaxError error) {
interstitialAd = null;
startActivity(new Intent(StartActivity.this, MainActivity.class));
StartActivity.this.finish();
}
}
Try this Code....