當抽屜中進行選擇時,我的應用程序使用導航抽屜並替換主要活動中的片段。我有幾個片段顯示Web視圖。如果我打開抽屜並選擇一個不同的項目,從而在Web視圖中的頁面加載完成之前用Web視圖替換片段,則會出現問題。發生這種情況時,出現此錯誤:在WebView加載之前替換片段時應用程序崩潰
12-02 08:07:48.605 11745-11745/kyfb.android.kyfb.com.kyfb A/chromium﹕ [FATAL:jni_android.cc(271)] Check failed: false.
12-02 08:07:48.605 11745-11745/kyfb.android.kyfb.com.kyfb A/libc﹕ Fatal signal 6 (SIGABRT), code -6 in tid 11745 (d.kyfb.com.kyfb)
這是帶有webview的片段之一。
public class AnnualMeetingFragment extends Fragment {
private WebView web;
private ProgressBar progressBar;
private String url;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(R.layout.fragment_ag_facts, null);
url = "http://www.kyfbnewsroom.com/2013-kentucky-farm-bureau-annual-meeting-program/";
web = (WebView)rootView.findViewById(R.id.web);
progressBar = (ProgressBar)rootView.findViewById(R.id.prgPageLoading);
web.getSettings().setDomStorageEnabled(true);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setSupportZoom(true);
web.getSettings().setBuiltInZoomControls(true);
web.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
web.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
web.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
web.loadUrl(url);
web.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView webView, int progress) {
getActivity().setProgress(progress * 100);
progressBar.setProgress(progress);
}
});
web.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(web, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(web, url);
progressBar.setProgress(0);
progressBar.setVisibility(View.GONE);
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getActivity(), description, Toast.LENGTH_SHORT).show();
}
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if(url.endsWith(".mp4") || url.endsWith(".3gp") || url.endsWith(".avi") || url.endsWith(".flv")){
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); //warning no error handling will cause force close if no media player on phone.
return true;
}
view.loadUrl(url);
return true;
}
});
return rootView;
}
}
webview是一個片段? – 2014-12-02 13:20:11
你能用你的webView爲我們提供代碼嗎? – Anatol 2014-12-02 13:25:01
當你移除'super.onCreateView(...)'時會發生什麼? – Randy 2014-12-02 13:47:24