Application crashes when onBackPress at loading conditions on the webview

0

I have an Error like this

01-28 14:16:11.214 mobile.android.tribun.daerah.jambi A/libc: Fatal signal 6 (SIGABRT) at 0x00007b70 (code=-6), thread 31600 (un.daerah.jambi) 01-28 14:16:12.074 ? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! 01-28 14:16:12.074 ? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!

I run a webview in one activity and the webview runs fine, but if there are cases where the webview is being loaded and I am doing onBackPressed then a crash occurs. Error crash shows as above. Here my snippet code

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

        }
    }

}

UPDATE ERROR

01-28 14:35:58.484 mobile.android.tribun.daerah.jambi A/libc: Fatal signal 6 (SIGABRT) at 0x00000267 (code=-6), thread 615 (un.daerah.jambi) 01-28 14:35:59.294 ? E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! 01-28 14:35:59.324 ? E/InputDispatcher: channel '431e6440 mobile.android.tribun.daerah.jambi/mobile.android.tribun.daerah.jambi.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 01-28 14:35:59.324 ? E/InputDispatcher: channel '432eab68 mobile.android.tribun.daerah.jambi/mobile.android.tribun.daerah.jambi.NewReadingActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 01-28 14:35:59.654 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener 01-28 14:35:59.654 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.dispatchApplyWindowInsets 01-28 14:35:59.674 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.onApplyWindowInsets 01-28 14:35:59.674 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method android.support.v4.view.ViewCompat.removeOnUnhandledKeyEventListener 01-28 14:35:59.684 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$1', referenced from method android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener 01-28 14:35:59.694 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.support.v4.widget.DrawerLayout$1', referenced from method android.support.v4.widget.DrawerLayout. 01-28 14:35:59.694 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.widget.DrawerLayout.onDraw 01-28 14:35:59.704 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.widget.DrawerLayout.onMeasure 01-28 14:35:59.704 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.widget.DrawerLayout.onMeasure 01-28 14:35:59.754 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 01-28 14:36:02.384 mobile.android.tribun.daerah.jambi E/dalvikvm: Could not find class 'dalvik.system.DelegateLastClassLoader', referenced from method ab.b 01-28 14:36:03.294 mobile.android.tribun.daerah.jambi E/AudioManagerAndroid: BLUETOOTH permission is missing!

UPDATE I know the suspect that causing this crash it was progress on ChromeClient, if i do comment out all code inside onProgress like below, it works perfectly:

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

But, i need to do it in order to handle progress UI. Any advise?

android
webview
onbackpressed
asked on Stack Overflow Jan 28, 2019 by Nanda Z • edited Feb 12, 2019 by Nanda Z

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0