I have activity with web browsing. It seems that web browsing does not collapse along with activity. To demonstrate, I created an html page that starts a timer that loads an image resource every few seconds. The script continues execution after the activity is destroyed:
public class MyWebViewActivity extends Activity { private WebView mWebView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.the_layout); mWebView = (WebView)findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setBuiltInZoomControls(true); mWebView.setWebViewClient(new EmbeddedWebViewClient()); mWebView.loadUrl("test url"); } private class EmbeddedWebViewClient extends WebViewClient { @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); if (Config.DEBUG) { Log.v(TAG, "onLoadResource(): " + url); } } } }
So the above just prints a log statement whenever onLoadResource () is called. Here's the javascript on the html test page:
<html> <head> <script type="text/javascript"> function load() { setInterval("doit()", 3000); } function doit() { Image1 = new Image(150, 20); Image1.src = "abc_" + Math.floor(Math.random()*100) + ".png"; } </script> </head> <body onload="load()"> </body> </html>
The above simply creates an image resource on a timer interval to run the onLoadResource () method in EmbeddedWebViewClient ().
So, I see in LogCat that messages continue to print after exiting this activity. Do we need to close the WebView somehow? Perhaps this is the problem described here:
http://code.google.com/p/android/issues/detail?id=9375
If this is a known issue, if it has been documented in api docs?
Note. Doing this on Android 2.3.4, Nexus S.
thanks
android
user291701
source share