I have an app that I\'ve put together to stream flash video in a webview when a user clicks a button.
It does this fine, but after backing out or losing focus, it lo
Calling webvew.destroy()
in onDestroy()
worked for me.
The webViwe destory approach did not work for me - it worked well on the first close of the webview, but subsequent calls to the webview caused a crash.
I ended up doing this:
_webView.loadData("", "text/html", "utf-8");
from my activity finish() method.
If you are as lucky as I am, even this won't be enough to end a youtube streaming! The sound is still playing no matter what!
@Override
protected void onDestroy() {
super.onDestroy();
// Stopping a webview and all of the background processes (flash,
// javascript, etc) is a very big mess.
// The following steps are to counter most of the issues seen on
// internals still going on after the webview is destroyed.
mWebView.stopLoading();
mWebView.loadData("", "text/html", "utf-8");
mWebView.reload();
mWebView.setWebChromeClient(null);
mWebView.setWebViewClient(null);
RelativeLayout layout = (RelativeLayout) findViewById(R.id.webviewRelativeLayout);
layout.removeView(mWebView);
mWebView.removeAllViews();
mWebView.clearHistory();
mWebView.destroy();
mWebView = null;
}
I combined some of the answers here, and this worked for me:
@Override
protected void onDestroy()
{
super.onDestroy();
webView.stopLoading();
webView.loadData("", "text/html", "utf-8");
webView.destroy();
}
This approach works me. I call it on back button press.
webview.stopLoading();
webview.loadUrl("");
webview.reload();
webview = null;
I'm a bit confused by the question, but I think you're saying that flash video keeps on playing even after the activity is closed. I ran into a similar issue. The following worked for me:
@Override
protected void onDestroy() {
super.onDestroy();
final WebView webview = (WebView)findViewById(R.id.webPlayer);
// Calling .clearView does not stop the flash player must load new data
webview.loadData("", "text/html", "utf-8");
}
I posted this same solution here: android WebView stop Flash plugin onPause