我陷入了以下问题!我解析网站,这是我的大概代码:
public class MainActivity extends Activity {
String CurURL = "";
@Override
public void onCreate(Bundle savedInstanceState) {
webview.setWebViewClient(new ForumWebViewClient());
new ParseMyPageTask().execute(url);
}
private class ForumWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView webview, String url) {
new ParseMyPageTask().execute(url);
return true;
}
}
public class ParseMyPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
*JSoup work*
return result;
}
@Override
protected void onPostExecute(String result) {
webview.loadDataWithBaseURL("http:..", result, "text/html", "UTF-8", CurURL);
}
}
@Override
public void onBackPressed() {
if (webview.canGoBack()) {
webview.goBack();
return;
}
super.onBackPressed();
}
}
按下后退按钮后,我应该为 AsyncTask 执行 url 做什么?现在它按原样返回页面,未解析。