如何销毁WebView Activity和WebView中的视频?
我在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);
}
}
}
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您使用之前,我们认为您至少需要了解这一点。
LINK1
和
LINK2
编辑
始终使用应用程序上下文实例化 webview。
如果你想要 xml 格式的 webview。扩展它
并像这样使用它
,并在您不再需要视图的所有地方调用它。
因为有时候Activity.onDestroy、Activity.onStop可能不会被调用。
before you use we view you need to be aware of atleast this.
LINK1
and
LINK2
EDIT
always instantiate webview using application context.
if you want webview in xml. extend it
and use it like this
and call this in all the places where you don't want the view any more.
because there are times when Activity.onDestroy, Activity.onStop may not be called.