android - Audio in webview continues to play in background -
i have webview audio player. if start audio , press return previous activity, audio still keeps playing in background. problem occurs when api lower 11.
my code:
@override public void finish() { if (android.os.build.version.sdk_int >= build.version_codes.honeycomb) { webview.onpause(); } else { webview.loadurl("about:blank"); } }
i tried
webview.loaddata("", "text/html", "utf-8");
and
webview.clearcache(true); webview.clearhistory(); webview.destroy();
but didn't work.
does know how solve that?
this solves problem fro api > 11
@override public void onpause() { super.onpause(); if(webview != null) { webview.onpause(); } } @override public void onresume() { super.onresume(); if (webview != null) { webview.onresume(); } }
but lower versions (in case) need call onpause
, onresume
follows
@override public void onpause() { super.onpause(); if(build.version.sdk_int >= build.version_codes.honeycomb){ webview.onpause(); } else { try { class.forname("android.webkit.webview") .getmethod("onpause", (class[]) null) .invoke(webview, (object[]) null); } catch(classnotfoundexception cnfe) { ... } catch(nosuchmethodexception nsme) { ... } catch(invocationtargetexception ite) { ... } catch (illegalaccessexception iae) { ... } } } @override public void onresume() { super.onpause(); if(build.version.sdk_int >= build.version_codes.honeycomb){ webview.onresume(); } else { try { class.forname("android.webkit.webview") .getmethod("onresume", (class[]) null) .invoke(webview, (object[]) null); } catch(classnotfoundexception cnfe) { ... } catch(nosuchmethodexception nsme) { ... } catch(invocationtargetexception ite) { ... } catch (illegalaccessexception iae) { ... } } }
Comments
Post a Comment