我有一个名为List<Website>
的历史记录,其中包含Website
s,String-String-Uri组的简单包装器。
现在,该列表是某种历史记录&#34;对于活动中的webview。
问题是,它不起作用。
我现在正在做的是:
网站:
public class Webpage implements Serializable {
protected String url;
protected String title;
protected Uri uri;
public Webpage(String title, String url) {
// ...
}
// Getters and other methods
public JSONObject toJSONObject() throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("title", this.title);
jsonObject.put("url", this.url);
return jsonObject;
}
public String serialize(int indentationLevel) {
try {
return toJSONObject().toString(indentationLevel);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
public String serialize() {
return serialize(4);
}
public static Webpage deSerialize(JSONObject object) throws JSONException {
return new Webpage(((String)object.get("title")), ((String)object.get("url")));
}
public static Webpage deSerialize(String jsonObject) throws JSONException {
return deSerialize(new JSONObject(jsonObject));
}
}
WebViewClient:
// ...
@Override public void onPageFinished(WebView view, String urlStr) {
OpenTabsActivity.history
.ensureCapacity(OpenTabsActivity.history.size+2)
OpenTabsActivity.history.add(new Webpage(webView.title, urlStr));
check();
setTitle(webView.title);
loadingBar.setProgress(0);
loadingBar.setVisibility(View.INVISIBLE);
super.onPageFinished(view, urlStr);
}