I was looking for a lot to fix this problem, but apparently I could not find it. Well, as the name implies, I have a simple Android app that has a web view.
public class MainActivity extends Activity { protected FrameLayout webViewPlaceholder; protected WebView webView; final Context myApp = this; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize the UI initUI(); } protected void initUI() { // Retrieve UI elements webViewPlaceholder = ((FrameLayout)findViewById(R.id.webViewPlaceholder)); // Initialize the WebView if necessary if (webView == null) { // Create the webview webView = new WebView(this); webView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setScrollbarFadingEnabled(true); webView.getSettings().setLoadsImagesAutomatically(true); // Load the URLs inside the WebView, not in the external web browser webView.setWebViewClient(new WebViewClient()); //webView.setWebChromeClient(new CustomChromeClient(this)); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result) { new AlertDialog.Builder(myApp) .setTitle("javaScript dialog") .setMessage(message) .setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }) .setCancelable(false) .create() .show(); return true; }; public void onShowCustomView(View view, CustomViewCallback callback){ super.onShowCustomView(view, callback); Log.i("ChromeCLient", "onshowCustomView"); new AlertDialog.Builder(myApp) .setTitle("javaScript dialog") .setMessage("ajbdlsakndsland") .setCancelable(true) .create() .show(); } @Override public void onHideCustomView() { super.onHideCustomView(); Log.i("ChromeCLient", "onhideCustomView"); } }); webView.getSettings().setJavaScriptEnabled(true); if (Build.VERSION.SDK_INT < 8) { webView.getSettings().setPluginsEnabled(true); } else { webView.getSettings().setPluginState(WebSettings.PluginState.ON); } // Load a page webView.loadUrl("http://jsbin.com/ijixe4/3"); } // Attach the WebView to its placeholder webViewPlaceholder.addView(webView); } @Override public void onConfigurationChanged(Configuration newConfig) { if (webView != null) { // Remove the WebView from the old placeholder webViewPlaceholder.removeView(webView); } super.onConfigurationChanged(newConfig); // Load the layout resource for the new configuration setContentView(R.layout.activity_main); // Reinitialize the UI initUI(); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // Save the state of the WebView webView.saveState(outState); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); // Restore the state of the WebView webView.restoreState(savedInstanceState); } }
My problem is as follows. A website that is uploaded to a web view is a site that contains a simple embedded iframe video. When I click the FullScreen button on the youtube video, it changes the orientation of my application, although I set in my manifest: screenOrientation = "portrait". When you exit FullScreen during playback, the video continues to play (in the background), although the web view has been recreated due to a change in orientation. I tried to destroy the web view in the onDestroy () method of the activity when the orientation moves from landscape to portrait. but it did not help. I tried setting up CustomWebChromeClient for web browsing and implementing the onShowCustomView () method, but onShowCustomView () does not seem to be called unless I use HTML5 video. I even tried to keep the state of the web view through a change in orientation.
Do you guys have another way to solve this problem / error? I would not want to use the HTML5 HTML tag. Thanks in advance.
source share