How to stop Flash after exiting WebView?

I have an application that I compiled for streaming flash video in a web browser when a user clicks a button.

It does it well, but after maintaining or losing focus, it looks like it continues to use the data for a while, until I assume that the system turns off activity. If I manually turn off the activity screen, data usage will stop almost immediately. Just retreat, and this may go on for some time.

Can someone help me with my code, I would really appreciate it!

import java.lang.reflect.Method; import android.app.Activity; import android.os.Bundle; import android.webkit.WebSettings; import android.webkit.WebView; public class Video extends Activity { private WebView webview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video); webview = (WebView) findViewById(R.id.webview); // resumeTimers() to account for the webview refcount bug (hopefully) webview.resumeTimers(); WebSettings webSettings = webview.getSettings(); webview.getSettings().setJavaScriptEnabled(true); webSettings.setPluginsEnabled(true); webview.setVerticalScrollBarEnabled (false); webview.setHorizontalScrollBarEnabled (false); webview.loadUrl("http://www.nasa.gov/multimedia/nasatv/nasatv_android_flash.html"); } @Override protected void onPause() { pauseBrowser(); super.onPause(); } @Override protected void onResume() { resumeBrowser(); super.onResume(); } private void pauseBrowser() { // pause flash and javascript etc callHiddenWebViewMethod(webview, "onPause"); webview.pauseTimers(); } private void resumeBrowser() { // resume flash and javascript etc callHiddenWebViewMethod(webview, "onResume"); webview.resumeTimers(); } private void callHiddenWebViewMethod(final WebView wv, final String name){ if( webview != null ){ try { Method method = WebView.class.getMethod(name); method.invoke(webview); } catch (final Exception e) { } } } } 
+11
android flash webview android-webview
Jun 01 2018-11-11T00:
source share
6 answers

I'm a little confused by the question, but I think you say that the flash video continues to play even after the activity is closed. I ran into a similar problem. 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 the same solution here: android webview stop the onPause Flash plugin

+13
Sep 08 '11 at 17:44
source share

This approach works. I click it on the back button.

 webview.stopLoading(); webview.loadUrl(""); webview.reload(); webview = null; 
+9
Sep 16 '12 at 18:18
source share

Calling webvew.destroy() on onDestroy() worked for me.

+4
Jan 18 2018-12-18T00:
source share

The webViwe-based approach didn’t work for me - it worked well the first time I closed the web browser, but subsequent calls to the web browser failed.

I ended up with this:

_webView.loadData ("," text / html "," utf-8 ");

from my activity finish () method.

+1
Nov 04
source share

If you're as lucky as I am, even that won't be enough to end youtube streaming! Sound still plays 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; } 
+1
Feb 19 '13 at 16:49
source share

I have combined some answers here and it worked for me:

 @Override protected void onDestroy() { super.onDestroy(); webView.stopLoading(); webView.loadData("", "text/html", "utf-8"); webView.destroy(); } 
+1
Apr 14 '14 at 16:03
source share



All Articles