WebView 사용 시 history가 누적되었을 경우,
Back을 눌렀을 때 WebView가 띄워진 Activity를 바로 종료하지 않고
WebView의 첫 화면으로 돌아간 후 다시 Back을 누르면 Activity를 종료(Back의 원래 기능).
해당 기능 구현을 위해 onBackPressed를 Override.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} | |
} |
'Android' 카테고리의 다른 글
[android]Bitmap 이미지 후광효과(BlurMaskFilter, extractAlpha) (2) | 2013.07.29 |
---|---|
[android]fragment show(visible) & hide(gone) (0) | 2013.07.22 |
[android]Changes for v4 Support Library _ revision 13 (May 2013) (0) | 2013.05.22 |
[android]Button의 Drawable을 SourceCode로 작성 (0) | 2013.05.15 |
[android]Bitmap to NinePatch (0) | 2013.05.13 |