3

I am playing HTML 5 Video in activity that is working fine, but when i press back button get exit from the activity and slide(Video contains by slides) but sound is still playing in background of that particular slide until it gets finish. How can i stop that sound while pressing the back button get exit completely form the activity.

here is my code when i press back button:

@Override
protected void onPause() {
    super.onPause();
    mWebView.stopLoading();
}

@Override
public void onStop() {
    super.onStop();
    mWebView.stopLoading();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (mWebView.inCustomView()) {
            mWebView.hideCustomView();
            mWebView.stopLoading();
            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}

@Override
public void onBackPressed() {
    if (mWebView.isFocused() && mWebView.canGoBack()) {
        mWebView.goBack();

    } else {
        super.onBackPressed();
        activity.finish();
    }
   }
 }
user3154663
  • 291
  • 1
  • 2
  • 18

2 Answers2

3

Try mWebView.destroy() or maybe load some dummy URL.
Like:

@Override
public void onBackPressed() {
    if (mWebView.isFocused() && mWebView.canGoBack()) {
        mWebView.goBack();

    } else {
        super.onBackPressed();
        activity.finish();
        mWebView.destroy();
    }
   }
NickF
  • 5,637
  • 12
  • 44
  • 75
  • This answer should be the correct answer, because if you call mWebView.destroy() BEFORE you call finish(), WebView is still attached to the activity, so you can't destroy it after the activity has been finished. – marienke Sep 17 '14 at 09:00
3

Put below line in your onStop() method:

mWebView.destroy();
rupesh
  • 2,865
  • 4
  • 24
  • 50