In my android application I want to open a webpage in a Webview
. A webpage which i want to open also contains video. To achieve this functionality, I used WebChromeClient
in my application. The problem is that, OnBackPressed()
of this activity, some videos don't get stopped and they keep playing in background, though my Webview activity is finished. I don't know why this happens. I tried various codes, but couldn't solve this problem. Some videos stop automatically, but some keeps on playing in background. How to solve this issue ?
Please help me to solve this problem.
Here is my code :
@Override
protected void onDestroy() {
super.onDestroy();
Log.e("Test HTML5:-", "onDestroy Called...");
mWebView.stopLoading();
// mWebView.clearCache(true);
// mWebView.clearHistory();
// mWebView.pauseTimers();
abc.removeView(mWebView);
mWebView.removeAllViews();
mWebView.destroy();
mWebView = null;
finish();
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
write this code on onPause()