我有这样的错误
01-28 14:16:11.214 mobile.android.tribun.daerah.jambi A / libc:致命的 信号3(SIGABRT)位于0x00007b70(代码= -6),线程31600 (un.daerah.jambi)01-28 14:16:12.074吗? E / JavaBinder:!!!失败的粘合剂 交易!!! 01-28 14:16:12.074? E / JavaBinder:!!!失败的粘合剂 交易!!!
我在一个活动中运行了一个webview,并且该webview运行良好,但是如果在某些情况下正在加载该webview,而我正在执行onBackPressed,则会发生崩溃。错误崩溃显示如上。 这是我的代码段
public class WebReadingActivity extends AppCompatActivity {
public static final String EXTRA_URL_NEWS = "extra_url_news";
private Unbinder unbinder;
@BindView(R.id.toolbar)
Toolbar toolbar;
@BindView(R.id.progress_frame)
FrameLayout progressbarFrame;
@BindView(R.id.progress_bar_line)
ProgressBar progressBar;
@BindView(R.id.webview_news)
WebView webViewNews;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_reading);
unbinder = ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
String urlData = getIntent().getStringExtra(EXTRA_URL_NEWS);
configureProgressbarLine();
loadNewsByWeb(urlData);
}
private void configureProgressbarLine(){
progressBar.setMax(100);
}
private void loadNewsByWeb(String url) {
webViewNews.setWebViewClient(new WebReadingClient());
webViewNews.setWebChromeClient(new ChromeClient());
webViewNews.getSettings().setJavaScriptEnabled(true);
webViewNews.getSettings().setAppCacheEnabled(true);
webViewNews.getSettings().setDomStorageEnabled(true);
webViewNews.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webViewNews.getSettings().setSupportMultipleWindows(true);
webViewNews.getSettings().setSupportZoom(false);
webViewNews.getSettings().setBuiltInZoomControls(false);
CookieManager.getInstance().setAcceptCookie(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webViewNews.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(webViewNews, true);
}
webViewNews.loadUrl(url);
}
@Override
protected void onDestroy() {
webViewNews.stopLoading();
unbinder.unbind();
super.onDestroy();
}
@Override
public void onBackPressed() {
if(webViewNews.isFocused() && webViewNews.canGoBack()){
webViewNews.goBack();
}else {
super.onBackPressed();
}
}
class ChromeClient extends WebChromeClient{
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressbarFrame.setVisibility(View.VISIBLE);
progressBar.setProgress(newProgress);
setTitle("Loading...");
if(newProgress == 100){
progressbarFrame.setVisibility(View.GONE);
setTitle(view.getTitle());
}
super.onProgressChanged(view, newProgress);
}
}
public static class WebReadingClient extends WebViewClient{
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
Timber.d("OnReceiverError --> %s", error.getDescription());
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Timber.d("OnReceiverError --> %s",description);
}
}
}
更新错误
01-28 14:35:58.484 mobile.android.tribun.daerah.jambi A / libc:致命的 信号6(SIGABRT)位于0x00000267(代码= -6),线程615 (un.daerah.jambi)01-28 14:35:59.294? E / JavaBinder:!!!失败的粘合剂 交易!!! 01-28 14:35:59.324? E / InputDispatcher:通道 '431e6440 mobile.android.tribun.daerah.jambi / mobile.android.tribun.daerah.jambi.MainActivity (服务器)'〜通道无法恢复,将被处置! 01-28 14:35:59.324? E / InputDispatcher:通道'432eab68 mobile.android.tribun.daerah.jambi / mobile.android.tribun.daerah.jambi.NewReadingActivity (服务器)'〜通道无法恢复,将被处置! 01-28 14:35:59.654 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到课程 'android.support.v4.view.ViewCompat $ OnUnhandledKeyEventListenerWrapper', 从方法引用 android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener 01-28 14:35:59.654 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到类“ android.view.WindowInsets”,从 方法android.support.v4.view.ViewCompat.dispatchApplyWindowInsets 01-28 14:35:59.674 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到类“ android.view.WindowInsets”,从 方法android.support.v4.view.ViewCompat.onApplyWindowInsets 01-28 14:35:59.674 mobile.android.tribun.daerah.jambi E / dalvikvm:无法 查找类“ android.view.View $ OnUnhandledKeyEventListener”,已引用 从方法 android.support.v4.view.ViewCompat.removeOnUnhandledKeyEventListener 01-28 14:35:59.684 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到类'android.support.v4.view.ViewCompat $ 1', 从方法引用 android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener 01-28 14:35:59.694 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到类'android.support.v4.widget.DrawerLayout $ 1', 从方法android.support.v4.widget.DrawerLayout引用。 01-28 14:35:59.694 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到类“ android.view.WindowInsets”,从 方法android.support.v4.widget.DrawerLayout.onDraw 01-28 14:35:59.704 mobile.android.tribun.daerah.jambi E / dalvikvm:无法 查找类'android.view.WindowInsets',从方法引用 android.support.v4.widget.DrawerLayout.onMeasure 01-28 14:35:59.704 mobile.android.tribun.daerah.jambi E / dalvikvm:找不到类 从方法引用的“ android.view.WindowInsets” android.support.v4.widget.DrawerLayout.onMeasure 01-28 14:35:59.754 mobile.android.tribun.daerah.jambi E / dalvikvm:找不到类 从方法引用的“ android.graphics.drawable.RippleDrawable” android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 01-28 14:36:02.384 mobile.android.tribun.daerah.jambi E / dalvikvm: 找不到类“ dalvik.system.DelegateLastClassLoader”, 从方法ab.b 01-28 14:36:03.294引用 mobile.android.tribun.daerah.jambi E / AudioManagerAndroid:BLUETOOTH 权限丢失!
更新 我知道,造成崩溃的原因可能是ChromeClient上的进度,如果我确实注释掉onProgress内部的所有代码(如下所示),则效果很好:
class ChromeClient extends WebChromeClient{
@Override
public void onProgressChanged(WebView view, int newProgress) {
/* NO CRASH WILL OCCUR IF COMMENT OUT
progressbarFrame.setVisibility(View.VISIBLE);
progressBar.setProgress(newProgress);
setTitle("Loading...");
if(newProgress == 100){
progressbarFrame.setVisibility(View.GONE);
setTitle(view.getTitle());
}
*/
super.onProgressChanged(view, newProgress);
}
}
但是,我需要这样做才能处理进度UI。有什么建议吗?