本文介绍了在Imagebutton之后-> Webview Addmob无法启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题。.我的应用程序从一个开始屏幕开始,我可以在3个图像按钮之间进行选择,以打开3个不同的Web视图(3个URL)。在我的开始屏幕中,我有来自admob的 Smart_Banner,单击任何图像按钮后,我都切换到Web视图,在此WebView中,我的admob消失了,它不回来了!我是否必须在此处重建一个新的admob广告?伙计们,我需要一些真正的帮助!

I have a Little Problem..my App starts with a startscreen where i can choose between 3 imagebuttons to open 3 different webviews (3 URLs). In my startscreen i have my "Smart_Banner" from admob and after i click any imagebutton i Switch to the webview and in this WebView my admob disappears and it dont comes back! Do i have to rebuild a new admob advertise there? guys i need some real help!!

  public static boolean checkInternetConnection(Context context) {
    ConnectivityManager con_manager = (ConnectivityManager)
            context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (con_manager.getActiveNetworkInfo() != null
            && con_manager.getActiveNetworkInfo().isAvailable()
            && con_manager.getActiveNetworkInfo().isConnected()) {
        return true;
    } else {
        return false;
    }
}

private ImageButton Ilias_link;
private ImageButton Lsf_link;
private WebView mWebView;
private Context content;

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    if (!DetectConnection.checkInternetConnection(this)) {
        Toast.makeText(getApplicationContext(), "Du hast leider kein Internet", Toast.LENGTH_SHORT).show();
    } else {
        Ilias_link = (ImageButton) findViewById(R.id.ilias_link);
        mWebView = new WebView(this);
        Ilias_link.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {


                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.setAcceptCookie(true);
                mWebView.getSettings().setJavaScriptEnabled(true);
                mWebView.getSettings().setBuiltInZoomControls(true);
                mWebView.getSettings().setDisplayZoomControls(false);
                mWebView.getSettings().setSupportZoom(true);
                if (savedInstanceState == null)
                    mWebView.loadUrl("https://elearns02.fh-biberach.de/ilias3/login.php?target=&soap_pw=&ext_uid=&cookies=nocookies&client_id=HSBC&lang=de");
                mWebView.setWebViewClient(new WebViewClient());
                setContentView(mWebView);

            }



        });
        Lsf_link = (ImageButton) findViewById(R.id.lsf_link);
        mWebView = new WebView(this);
        Lsf_link.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mWebView.getSettings().setJavaScriptEnabled(true);
                mWebView.getSettings().setBuiltInZoomControls(true);
                mWebView.getSettings().setDisplayZoomControls(false);
                mWebView.getSettings().setSupportZoom(true);
                if (savedInstanceState == null)
                    mWebView.loadUrl("https://lsf.fh-biberach.de/qisserver/rds?state=user&type=0");
                mWebView.setWebViewClient(new WebViewClient());
                setContentView(mWebView);



            }


        });





    ImageButton imageButton = (ImageButton) findViewById((R.id.Mensaplan));
    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "Coming soon ;)", Toast.LENGTH_LONG).show();
        }
    });
}}

public void onPageFinished(WebView view, String url) {
    String javascript = "javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'initial-scale=1.0,maximum-scale=10.0');";
    view.loadUrl(javascript);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mWebView.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mWebView.restoreState(savedInstanceState);
}

private static final int TIME_INTERVAL = 3000;
private long mBackPressed;

@Override
public void onBackPressed() {
    if (mWebView.canGoBack()) {
        mWebView.goBack();
        return;
    } else {
        if (mBackPressed + TIME_INTERVAL > System.currentTimeMillis()) {
            super.onBackPressed();
            return;
        } else {
            Toast.makeText(getBaseContext(), "Press back button twice to exit ;)", Toast.LENGTH_SHORT).show();
        }
        mBackPressed = System.currentTimeMillis();




    }




}

}

推荐答案

您正在呼叫 setContentView(mWebView); 仅将WebView替换为Activity中的视图。即它将首先删除AdView(以及其他所有内容)。

You are calling setContentView(mWebView); which replaces the view in your Activity with just the WebView. Ie it will remove the AdView (and everything else) first.

这篇关于在Imagebutton之后-> Webview Addmob无法启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:22