问题
How do i get the history of a WebView using the WebBackForwardList class? I looked at the documentation page but i could not understand it, is WebBackForwardList the proper way to access the history of WebView? I intend to parse the history to a ListView, I cannot find any examples of how to access the history of WebView, What is the proper method to get the history?
回答1:
On your webView instance, just use copyBackForwardList(), for example
WebBackForwardList wbfl = webView.copyBackForwardList();
Then setup a for-loop to scan the list, pull entries (e.g., title, URL), and send them to your ListView (or whatever).
回答2:
Yeah, you can use WebBackForwardList
Example:
public void getBackForwardList(){
WebBackForwardList currentList = this.copyBackForwardList();
int currentSize = currentList.getSize();
for(int i = 0; i < currentSize; ++i)
{
WebHistoryItem item = currentList.getItemAtIndex(i);
String url = item.getUrl();
LOG.d(TAG, "The URL at index: " + Integer.toString(i) + " is " + url );
}
}
来源:https://stackoverflow.com/questions/19365668/getting-webview-history-from-webbackforwardlist