Applovin集成卡在进度对话框上



我正试图将Applovin插页广告整合到代码中,因此,如果点击"让我们开始"按钮,它应该显示一个进度对话框,因为它加载插页广告。在用户关闭插页广告或退出后,它会转到下一个类,也就是主活动。我正在运行的代码只是卡住了加载进度对话框部分。我怎样才能解决这个问题?

代码

公共类StartActivity扩展AppCompatActivity实现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();
}

}

试试这个代码....

public class StartActivity extends AppCompatActivity implements MaxAdListener {
final ProgressDialog pd;
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();

pd = new ProgressDialog(StartActivity.this);
pd.setCancelable(false);
pd.setMessage("Loading...");
pd.show();

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 -> {

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) {
if (pd != null) {
pd.dismiss();
}
startActivity(new Intent(StartActivity.this, MainActivity.class));
StartActivity.this.finish();
}
@Override
public void onAdClicked(MaxAd ad) {
if (pd != null) {
pd.dismiss();
}
}
@Override
public void onAdLoadFailed(String adUnitId, MaxError error) {
if (pd != null) {
pd.dismiss();
}
startActivity(new Intent(StartActivity.this, MainActivity.class));
}
@Override
public void onAdDisplayFailed(MaxAd ad, MaxError error) {
if (pd != null) {
pd.dismiss();
}
interstitialAd = null;
startActivity(new Intent(StartActivity.this, MainActivity.class));
StartActivity.this.finish();
}
}

相关内容

  • 没有找到相关文章

最新更新