With Android, when i use the back key from a web view a white screen appears

I am using a very simple activity displaying a WebView, but when I go back to the previous activity from a web view, a white screen appears, and I need to press again the back key to succeed. Is there a way to prevent this ?

The web activity Display_web.java:

public class Display_web extends Activity {
private WebView myWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String refOeuvre = intent.getStringExtra("REFOEUVRE");
    setContentView(R.layout.display_web);

    myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setDomStorageEnabled(true);
    myWebView.loadUrl(refOeuvre);
}

@Override
public void onBackPressed() {
    if(myWebView!=null && myWebView.canGoBack())
        myWebView.goBack();// if there is previous page open it
    else
        super.onBackPressed();//if there is no previous page, close app
}

}

The xml file display_web.xml:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

The activity where I call the new WebView, with a WebView and a ListView :

public class Display_alpha3 extends Activity {
public ListView mListOeuvres;
public WebView wikipediaCompo;

...... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.display_alpha3); Intent intent = getIntent(); ...... mListOeuvres = (ListView) findViewById(R.id.list_oeuvres);

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(Display_alpha3.this,
            android.R.layout.simple_list_item_1, infoOeuvres);

    wikipediaCompo = (WebView) findViewById(R.id.wikipediaCompo);
    WebSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webSettings.setDomStorageEnabled(true);
    wikipediaCompo.loadUrl(refCompo);
    wikipediaCompo.setWebViewClient(new WebViewClient()
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            return false;
        }
    });

    mListOeuvres.setAdapter(adapter);
    mListOeuvres.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String pos = String.valueOf(parent.getItemAtPosition(position));
            Intent i = new Intent(Display_alpha3.this, Display_web.class);
            i.putExtra("REFOEUVRE", refYouTube[position]);
            startActivity(i);
        }
    });
}

}

链接地址: http://www.djcxy.com/p/86066.html

上一篇: PostgreSQL简单JOIN非常慢

下一篇: 使用Android时,当我使用Web视图中的后退键时,会出现一个白色屏幕