谁能告诉我,为什么返回按钮返回一个黑页?我在 AsyncTask 中使用 Jsoup 进行解析。历史好像不存在。我应该在我的代码中更改什么来修复它?
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new ForumWebViewClient());
String url = "https://forum.com";
new ParseMyPageTask().execute(url);
}
private class ForumWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
new ParseMyPageTask().execute(url);
return true;
}
}
class ParseMyPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
Document doc = null;
String result = "";
try {
doc = Jsoup.connect(params[0]).get();
Elements body = doc.select("body");
result = body.html();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
webview.getSettings().setUseWideViewPort(true);
webview.setInitialScale(0);
webview.loadDataWithBaseURL("https://forum.com/",
"<head><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" /><link rel=\"stylesheet\" type=\"text/css\" href=\"/data/styles/black.css\"></head><body>" + result + "</body>", "text/html", "UTF-8", "");
}
}
public void onBackPressed() {
if (webview.canGoBack()) {
webview.goBack();
return;
}
super.onBackPressed();
}
我真的需要你的帮助!