WebView01.setWebViewClient(new WebViewClientClass()); 부분을
아래와 같이 Back button 을 위해서 사용한 것인데요. 주석 처리 했더니 backbutton이 먹질 않네요 ㅜㅜ; (어제 관련 내용에서 progress bar가 위의 WebViewClient를 두번 불러오는 것 때문에 안되는걸로 질문 했었습니다.)
혹시나 해서 윗부분의 WebView01.setWebViewClient(new WebViewClient()); 부분을 WebViewClientClass로 변동해 보았지만 백버튼이 여전히 묵묵무답입니다.
뭐가 문제일까요? 종일 삽질하는데 바보짓만 하는 기분입니다.
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private String site;
private WebView WebView01;
private String mCurrentUrl;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
// startActivity(new Intent(this, Splash.class));
progressBar = (ProgressBar) this.findViewById(R.id.pro);
site = http://m.naver.com;
WebView01 = (WebView) findViewById(R.id.webView1);
WebView01.getSettings().setJavaScriptEnabled(true);
WebView01.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
//WebView01.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
WebView01.setWebViewClient(new WebViewClientClass() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressBar.setVisibility(View.INVISIBLE);
WebView01.clearHistory();
WebView01.clearCache(true);
// WebView01.clearView();
}
/* public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(MainActivity.this, "로딩에러" + description, Toast.LENGTH_SHORT).show();
}*/
@SuppressWarnings("deprecation")
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(MainActivity.this, "불러오는중 에러가 발생 했습니다." + description, Toast.LENGTH_SHORT).show();
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
// Redirect to deprecated method, so you can use it in all SDK versions
onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
}
});
WebView01.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressBar.setProgress(newProgress);
}
});
WebView01.loadUrl(site);
// WebView01.setWebViewClient(new WebViewClientClass());
mCurrentUrl = null;
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private class WebViewClientClass extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (mCurrentUrl != null && url != null && url.equals(mCurrentUrl)) {
WebView01.goBack();
} else {
WebView01.loadUrl(site);
mCurrentUrl = url;
}
return true;
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && WebView01.canGoBack()) {
WebView01.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}