Without any doubts, Android SDK has a poor documentations. There are pitfalls and traps about APIs without any mentions in SDK documentations.
1. WebView.clearHistory()
When there is only one item in WebView’s internal back/forward list, clearHistory() won’t clear anything. When there are more than one items in back/forward list, clearHistory() will clear all the items except the top one, or the current one.
The next question you might ask is when WebView adds an item to its back/forward list when loading a URL. By listening WebChromeClient.onProgressChanged(), we can know this, when new progress is bigger than 10, the loading URL will be added to its back/forward list. So when new progress is bigger than 10, loading URL becomes current item and thus you can clear previous loaded URLs by calling clearHistory().
本文探讨了Android SDK中WebView.clearHistory()方法的行为特点。当WebView的前进/后退列表中仅有一个条目时,该方法不会清除任何内容。如果有多个条目,则只会保留当前页面。文章还解释了如何通过监听WebChromeClient.onProgressChanged()来确定何时添加新的URL到前进/后退列表。
2343

被折叠的 条评论
为什么被折叠?



