I have the weirdest bug. I am running this exact code to play a popular business podcast:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
webview.getSettings().setAppCacheEnabled(false);
webview.getSettings().setJavaScriptEnabled(true);
webview.setInitialScale(1);
webview.getSettings().setPluginState(PluginState.ON);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setAllowContentAccess(true);
webSettings.setEnableSmoothTransition(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setUseWideViewPort(true);
setContentView(webview);
webview.loadUrl("http://www.stitcher.com/podcast/entrepreneuronfirecom/entrepreneur-on-fire-tim-ferriss-other-incredible-entrepreneurs");
And it works just fine, and I am able to play the podcasts, but the problem is that when I leave the screen, the podcast keeps on playing.
Would anyone know what needs to be done to prevent that behavior?
Thanks, Alex
Do something in onStop()
, such as load a blank page into the WebView
, or perhaps call clearView()
on it.
The "bug" that you are seeing is no different than how desktop browsers behave. If you load that URL in a desktop browser, and you switch to a different tab in the browser, or minimize the browser window, the podcast keeps playing.