问题更新:返回按钮的问题神秘地解决了。 现在它在开始新活动时崩溃了(全屏播放器)
我在四个条件下测试了我的应用程序:
1.在出现的WebView之前按下按钮:它工作正常
2.在WebView中播放YouTube视频时按下按钮:它工作正常
3. WebView完成播放后按下按钮:工作正常
4。在WebView出现之后但在单击播放按钮之前按下按钮:它崩溃
我的代码如下:
@Override
public void onCreate(Bundle savedInstanceState) {
// Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onCreate(savedInstanceState);
webview = (WebView) findViewById(R.id.web_view_player_vertical);
webview.clearCache(true);
webview.clearHistory();
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginState(PluginState.ON);
webview.getSettings().setPluginsEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);// completely zoomed out
webview.getSettings().setUseWideViewPort(true);
webview.getTouchables();
webview.setBackgroundColor(Color.parseColor("#00000000"));
webview.setWebChromeClient(new WebChromeClient());
webview.setWebViewClient(new WebViewClient());
webview.loadUrl(emdLink);
}
@Override
public void onPause() {
super.onPause();
try {
Log.i("in onpause", "onpause try");
Class.forName("android.webkit.WebView")
.getMethod("onPause", (Class[]) null)
.invoke(webview, (Object[]) null);
Log.i("in onpause", "onpause tried");
} catch (ClassNotFoundException cnfe) {
} catch (NoSuchMethodException nsme) {
} catch (InvocationTargetException ite) {
} catch (IllegalAccessException iae) {
} catch (Exception all) {
Log.i("Exception", "Exception : "+all );
}
webview.destroy();
}
public void FullScreenFunction(){
Log.v("FullScreenFunction", "durationPass :: " + duration);
Log.v("FullScreenFunction", SrcPath1);
Bundle bundle = new Bundle();
bundle.putString("duration", duration);
bundle.putString("link", SrcPath1);
bundle.putString("youtubeLink", youtubeLink);
bundle.putString("thumbnailLink", thumbnailLink);
bundle.putString("title", title);
bundle.putString("id", VideoId);
bundle.putString("view_count", viewCount);
bundle.putString("uploaded_date", date);
Log.v("FullScreenFunction", "start");
Intent myIntent = new Intent(this, HdPlayerHorizontal.class);
myIntent.putExtras(bundle);
startActivity(myIntent);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "onDestroy", Toast.LENGTH_LONG).show();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Toast.makeText(this, "onStop", Toast.LENGTH_LONG).show();
}
@Override
public void onResume() {
super.onResume();
Log.v("onResume", "onResume");
}
任何形式的帮助将不胜感激。提前谢谢!
以下是来自logcat的消息:
I/ActivityManager(1872): START {HdPlayerHorizontal (has extras)} from pid 13552
I/onPuase(13552): onPuase
I/in onpause(13552): onpause try
I/in onpause(13552): onpause tried
D/webviewglue(13552): nativeDestroy view: 0xc7b8d0
A/libc(13552): Fatal signal 11 (SIGSEGV) at 0x00d84c18 (code=2)
答案 0 :(得分:2)
致命信号11是因为webview在您销毁之后仍在绘制。只需将webView.destroy()放在onStop中即可。我相信你的应用程序可以正常工作