【问题标题】:How can I destroy the WebView Activity and the video in WebView?如何销毁 WebView 活动和 WebView 中的视频?
【发布时间】:2011-08-23 04:54:42
【问题描述】:

我在webview中播放了一个swf视频,当我按back_key时,声音仍然存在..我不知道如何破坏它...请帮助我,代码如下:

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);
        }
    }
}

【问题讨论】:

    标签: android video flash android-webview


    【解决方案1】:

    在您使用之前,我们认为您至少需要了解这一点。

    LINK1

    LINK2

    编辑

    始终使用应用程序上下文实例化 webview。

    webView = new WebView(getApplicationContext());
    

    如果你想要 xml 中的 webview。扩展它

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

    并像这样使用它

    <com.myapp.MyWebView ...
    

    并在您不再需要该视图的所有地方调用它。

    webView.destroy();    
    

    因为有时候Activity.onDestroy,Activity.onStop可能不会被调用。

    【讨论】:

    • 你能给我一个更直接和相对的答案吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多