Skip to content

Instantly share code, notes, and snippets.

@aggapple
Created April 27, 2017 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aggapple/68b5b62cb5af97725db5ff5ec9548962 to your computer and use it in GitHub Desktop.
Save aggapple/68b5b62cb5af97725db5ff5ec9548962 to your computer and use it in GitHub Desktop.
[android]WebView history stack & back
@Override
public void onBackPressed() {
// 누적된 history를 저장할 변수
WebBackForwardList list = mWebView.copyBackForwardList();
if (list.getCurrentIndex() <= 0 && !mWebView.canGoBack()) {
// 처음 들어온 페이지이거나, history가 없는경우
super.onBackPressed();
} else {
// history가 있는 경우
// 현재 페이지로 부터 history 수 만큼 뒷 페이지로 이동
mWebView.goBackOrForward(-(list.getCurrentIndex()));
// history 삭제
mWebView.clearHistory();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment