0

I played a swf video in a webview, when I press back_key, the sound still exists.. I don't know how to destroy it...plz help me, code is as following:

public class Video extends Activity {
    private WebView webview = null;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        Intent intent = getIntent();
        String url = intent.getExtras().getString("Url");
        Log.i("URL OF VIDEO IS", url);
        setTitle("Video");
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.webpageview);
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setPluginsEnabled(true);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl(url);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            //How can I destroy the Activity? I tried finish() it, but it doesn't works.
            webview.removeAllViews();
            return super.onKeyDown(keyCode, event);
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
}
Mark
  • 11
  • 1
  • 1
  • 5

1 Answers1

2

before you use we view you need to be aware of atleast this.

LINK1

and

LINK2

EDIT

always instantiate webview using application context.

webView = new WebView(getApplicationContext());

if you want webview in xml. extend it

    public MyWebView(Context context, AttributeSet attrs) {
    super(getApplicationContext(), attrs);
}

and use it like this

<com.myapp.MyWebView ...

and call this in all the places where you don't want the view any more.

webView.destroy();    

because there are times when Activity.onDestroy, Activity.onStop may not be called.

Community
  • 1
  • 1
Samuel
  • 9,883
  • 5
  • 45
  • 57