I am developing an Phonegap app(Android), which uses javascript/HTML5 localStorage. The app works fine, however when I add the Admob to the app, the localStorage not work. Meaning the stored values are delete when the app is force closed or the phone is restarted.
public class TestActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
// ADMOB: If comment, work.
/*
LinearLayout layout = super.root;
AdView adView = new AdView(this, AdSize.BANNER, **MY_CODE_ADMOB**);
layout.addView(adView);
AdRequest request = new AdRequest();
adView.loadAd(request);
*/
}
}
Thanks!!
You have to delay the code that launches the ad by a few seconds...below worked for me.
public class youActivity extends DroidGap {
private Handler mHandler = new Handler();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
mHandler.postDelayed(new Runnable() {
public void run() {
doStuff();
}
}, 5000);
}
private void doStuff() {
final String MY_AD_UNIT_ID = "yourAD_UNIT_ID";
AdView adView;
// Create the adView
adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
LinearLayout layout = super.root; // this is the only change from the sample
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With