this is my first question here, I hope I'm not asking something repeated.

I'm making an Android app that consist in just a WebView. The problem is that onResume() doesn't load my web again. I have some external links that open other apps (the browser, the Twitter app, etc) and when I want to go back to my app it shows the background from the LinearLayout and it doesn't loads the WebView. I have the same problem when I lock the screen, it shows a blank screen (my background actually) after unlock.

It's my first time with Android so I can't figure how it all works, here is my code for onPause():

@Override
public void onPause() {
    myWebView.setVisibility(WebView.GONE);
    myWebView.destroy();
    super.onPause();
}

And this is the code for onCreate(), I don't know if something else is relevant for this problem:

WebView myWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {

    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    this.setContentView(R.layout.activity_main);
    super.onCreate(savedInstanceState);
    if (!DetectConnection.checkInternetConnection(this)) {
        Toast.makeText(getApplicationContext(), "No conn message", Toast.LENGTH_LONG).show();        


    myWebView = (WebView) findViewById(R.id.webView);
        myWebView.setBackgroundColor(0);        
        myWebView.setBackgroundResource(R.drawable.background_wv);
        myWebView.getSettings().setBuiltInZoomControls(true);
        myWebView.getSettings().setSupportZoom(true);
        myWebView.getSettings().setUseWideViewPort(true);
        myWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
    } else {
        myWebView.loadUrl(myURL);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
        myWebView.setWebViewClient(new MyWebViewClient());
    }
}

Thank you!

PS: I have no onResume code.

有帮助吗?

解决方案

I will add the answer from my comment above:

You are destroying the webview in the onPause method and you are not recreating it back in the onResume. onCreate will not get called again once you come back to the app unless the activity itself got destroyed.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top