I am loading ads in a static manner on Activity's onCreate()
method if not already loaded and on onResume()
method. I am showing ads after 3-4 intervals.
Is it against google Admob's policy to show Interstitial ads on Activity
onResume()
?I've gone through this article, where it says: Do not place interstitial ads on app load, but not sure I am breaking it or not. am I?
And if user gets a phone call while using app, when he hangs up,
onResume()
is called again. So, it might show an Interstitial ad. Am i breaking the law: It should be clear to the user which application the ad is associated with or implemented on, mentioned here?
Simplified version of my code is given:
AdmobInterstitial.java
public class AdmobInterstitial {
private static InterstitialAd mInterstitialAd;
public static InterstitialAd getInterstitial(final Context context) {
if(mInterstitialAd==null)
{
final AdRequest adRequest= new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mInterstitialAd = new InterstitialAd(context.getApplicationContext());
mInterstitialAd.setAdUnitId(Utility.INTERSTITIAL);
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
mInterstitialAd.loadAd(adRequest);
}
});
mInterstitialAd.loadAd(adRequest);
}
return mInterstitialAd;
}
public static void counter(Application app, ShowAdInterface mmActivity)
{
SharedPreferences pref = app.getSharedPreferences(Utility.SHARED_PREF_NAME , MODE_PRIVATE);
SharedPreferences.Editor editor = pref.edit();
int my_counter=pref.getInt("banner_count",0);
if(my_counter>0&& my_counter%3==0) {
if(!mmActivity.showAd()) {
my_counter--;
}
}
my_counter++;
editor.putInt("banner_count",my_counter);
editor.apply();
}
}
ShowAdInterface
public interface ShowAdInterface {
public boolean showAd();
}
MainActivity.java
public class MainActivity extends AppCompatActivity implements ShowAdInterface{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mInterstitialAd= AdmobInterstitial.getInterstitial(this);
}
@Override
protected void onResume() {
super.onResume();
AdmobInterstitial.counter(getApplication(),this);
}
}