android


How to Preload Interstitial Ad in Android application


I am working on an android application and i have tried to implement Interstitial Ad but it takes 3 4 seconds to load and it causing accidental clicks on my app
Please help how to pre load my add so that it appears instantly on the next screen.
My code is here under:
public class AboutActivity extends AppCompatActivity {
private AdView mAdView;
private InterstitialAd interstitial;
#Override
protected void onCreate(Bundle savedInstanceState) {
interstitial = new InterstitialAd(AboutActivity.this);
interstitial = new InterstitialAd(getApplicationContext());
interstitial.setAdUnitId("ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX");
AdRequest adRequest1 = new AdRequest.Builder().build();
interstitial.loadAd(adRequest1);
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
if(interstitial.isLoaded()) {
interstitial.show();
}
}
});
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
}
}
interstitial.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
//Remove show() code from here
}
});
Don't call show() method on your interstitial Ad inside onAdLoaded() method. Make a method to show interstitial Ad and call that method when you want to show
public void showIntersitial(){
if(interstitial.isLoaded()) {
interstitial.show();
}else{
// Not loaded make a request to load
AdRequest adRequest1 = new AdRequest.Builder().build();
interstitial.loadAd(adRequest1);
}
}
You also need to add a listener to your Ad and make a new Ad request when you close your Interstitial Ad.

Related Links

Included layout covers parent layout
Possible to get install error code, like INSTALL_FAILED_VERIFICATION_FAILURE, by using some hook method or others?
How to set OnClick on Programmatically TableRow?
How to get copied bytes while copying file using file channels
Cannot install App on Android 6.0.1
Android support toolbar title margin
How pass taps outside Qt app window in Android?
Add View Below Toolbar in android
How to disable the list item click when listview is scrolled
Android AppBar and FAB won't elevate
How I can create a RecyclerView with fixed size image that wrap contents and image is crop centered
Why I have this rotation of image? [duplicate]
Uber deeplink Android app
How to create and write data a text file in android programatically? [duplicate]
I am getting this alert in Android developer console
Retrofit diffirent domains using

Categories

HOME
shell
uml
eclipse
porting
paraview
polymer
css3
phpmyadmin
interface
devise
ado.net
performancepoint
fosrestbundle
drop-down-menu
automatic-ref-counting
selenium-ide
package-managers
dynamic-sql
wolframalpha
delphi-xe5
charles
ksh
gulp-watch
named-entity-recognition
scriptella
ckfinder
game-theory
beautifier
outliers
linked-data
testcomplete
event-flow
dst
cognos-bi
simplecv
sendbird
pdw-file-browser
slacktextviewcontroller
mnist
dm-script
odoo-website
subclipse
claims
smoothstate.js
procfile
linter
yii2-api
skin
rackspace-cloud
branch-prediction
slackware
cudd
burrows-wheeler-transform
android-dateutils
vorpal.js
swizzling
cda
false-sharing
kendo-upload
jbase
concurrentmodification
fuelcms
eoferror
dronekit-android
liquid-layout
alloy-ui
telepat
entity-framework-4.3
java-security
code-documentation
ghcjs
mongohq
scringo
gpars
ui-select2
onload-event
apache-abdera
adobe-media-server
apache-whirr
oracle-enterprise-linux
ilasm
wiimote
apache-commons-dbutils
relative
expression-blend-4
cloudfiles
jqueryform
interprocess
eclipse-marketplace
zen
django-piston

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile