I am showing MoPub Interstitial ad
between to activities
.
When my device online/connect with internet. Then
adListener
work properly.This not work when device OFFLINE.
Situation: If ad
not loaded
or failed
then I want to use Intent
there to move next activity
. But this MoPubAdListener
not work when I am offline.
Interstitial mInterstitial.load()
in onCreate
method
When user press back button then Interstitial ad called
@Override
public void onBackPressed() {
try {
customProgressDialogForAd.show(getSupportFragmentManager(),"before interstitial");
funInterstitialLoadShow();
} catch (Exception e){
QuestionActivity.super.onBackPressed();
}
//super.onBackPressed();
}
function of Interstitial call
private void funInterstitialLoadShow(){
mInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial moPubInterstitial) {
Toast.makeText(QuestionActivity.this, "adloaded", Toast.LENGTH_SHORT).show();
mInterstitial.show();
customProgressDialogForAd.dismiss();
}
@Override
public void onInterstitialFailed(MoPubInterstitial moPubInterstitial, MoPubErrorCode moPubErrorCode) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
// PROBLEM HERE: THIS fun now work when Device is OFFLINE(NO INTERNET);
}
@Override
public void onInterstitialShown(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial moPubInterstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial moPubInterstitial) {
customProgressDialogForAd.dismiss();
QuestionActivity.super.onBackPressed();
}
});
}
Problem: onInterstitialFailed
not work when device not connected with internet. [on the other hand if internet is ON in device, then sdk works properly eg if we close ad then onInterstitialDismissed
works]
Any Solution: Please
There is two way/method/type, to call MoPub's
AdListener
.1st way: Direct call
adListener
2nd way: to call MoPub
AdListener
viaimplements
in ourActivity class
Solution:
You are not using
mInterstitial.load()
withadListener
. Without adding this line of code withAdListener
,functions ofAdlistener
not works because this line is part ofadListener
.Happy Coding :)