Code example for WebView

Methods: canGoBackdestroygoBack, removeAllViews

0
	} 
 
	@Override 
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// Check if the key event was the BACK key and if there's history 
		if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
			myWebView.goBack();
			return false; 
		} else if (keyCode == KeyEvent.KEYCODE_BACK) {
			LinearLayout layout = (LinearLayout) findViewById(R.id.playerLayout);
			layout.removeView(myWebView);
			myWebView.removeAllViews();
			closeTVPlayer(true); 
		} 
		return super.onKeyDown(keyCode, event);
	} 
 
	private void closeTVPlayer(boolean removeStatusBar) {
		if (myWebView != null) {
 
			if (!Stations.allowZoom().contains(stationName)) {
				myWebView.removeAllViews();
				myWebView.destroy();
			} else { 
				// to avoid a crash 
				// http://stackoverflow.com/questions/5267639/how-to-safely-turn-webview-zooming-on-and-off-as-needed 
				long timeout = ViewConfiguration.getZoomControlsTimeout();
				new Timer().schedule(new TimerTask() {
Contextual code suggestions in your IDE  Get Codota for Java