2016-04-07 54 views
0

我有一個小問題..我的應用程序以啓動畫面開始,我可以在3個圖像按鈕之間選擇以打開3個不同的Web視圖(3個URL)。在我的初始屏幕中,我從admob獲得了我的「Smart_Banner」,並且在點擊任何圖像按鈕之後,我切換到webview並在此WebView中,admob消失了,它不再回來!我必須重建一個新的admob在那裏做廣告嗎?傢伙,我需要一些真正的幫助!After Imagebutton - > Webview Addmob不會啓動

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




    } 




} 

}

+0

真的嗎?沒有人能幫助我?我認爲堆棧溢出有一些好的程序員... – Viru

回答

0

要調用setContentView(mWebView);與剛剛web視圖替換視圖中的活動。即它會首先刪除AdView(以及其他)。

+0

我該如何解決這個問題? – Viru

+0

而不是改變contentView,你應該在R.layout.activity_main有WebView元素,並使其中一個可見 – William

+0

好吧,我會嘗試thx!我是否也可以開始新的活動? – Viru