安卓+ HTML5(的localStorage)+ Admob的:错误? [英] Android + HTML5(LocalStorage) + Admob: Bug?

查看:155
本文介绍了安卓+ HTML5(的localStorage)+ Admob的:错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个PhoneGap的应用程序(安卓),它使用JavaScript / HTML5 localStorage的。该应用程序工作正常,但是当我添加Admob的到 该应用程序,在localStorage的无法工作。含义 存储的数据删除,当应用程序被强制关闭或手机 重新启动。

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);
        */
    }
}        

谢谢!

推荐答案

您已经耽误code,通过几秒钟启动广告......以下为我工作。

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());
}
}

这篇关于安卓+ HTML5(的localStorage)+ Admob的:错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆