0

I have an app that can have multiple WebViews. For testing i only use one WebView though. The WebView is refreshed every 15 minutes, and the app is just meant to be open all the time on the device as sort of a dashboard. The above works fine, but after a day or two the App will suddenly crash with the following message:

06-03 09:59:43.165 6243-6267/? A/libc: Fatal signal 5 (SIGTRAP), code -6 in tid 6267 (RenderThread)
06-03 09:59:43.227 310-310/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
06-03 09:59:43.228 310-310/? A/DEBUG: Build fingerprint: 'Lenovo/TB2-X30F/TB2-X30F:6.0.1/LenovoTB2-X30F/TB2-X30F_S000113_160816_ROW:user/release-keys'
06-03 09:59:43.228 310-310/? A/DEBUG: Revision: '0'
06-03 09:59:43.229 310-310/? A/DEBUG: ABI: 'arm'
06-03 09:59:43.230 310-310/? A/DEBUG: pid: 6243, tid: 6267, name: RenderThread  >>> namespace.of.app <<<
06-03 09:59:43.230 310-310/? A/DEBUG: signal 5 (SIGTRAP), code -6 (SI_TKILL), fault addr 0x1863
06-03 09:59:43.326 310-310/? A/DEBUG: Abort message: '[FATAL:memory_linux.cc(37)] Out of memory.
    '
06-03 09:59:43.327 310-310/? A/DEBUG:     r0 00000000  r1 00000000  r2 7fffffff  r3 00000000
06-03 09:59:43.327 310-310/? A/DEBUG:     r4 a34144e4  r5 0000002a  r6 a7c16c38  r7 0000002a
06-03 09:59:43.327 310-310/? A/DEBUG:     r8 a3414930  r9 a3414934  sl b6cc7e40  fp a34144e4
06-03 09:59:43.327 310-310/? A/DEBUG:     ip a34144a8  sp a34144d0  lr b6ca5459  pc a64f473c  cpsr 60070030
06-03 09:59:43.330 310-310/? A/DEBUG: backtrace:
06-03 09:59:43.330 310-310/? A/DEBUG:     #00 pc 015fb73c  /data/app/com.google.android.webview-2/lib/arm/libwebviewchromium.so

I simply have a a Runnable that handles the refreshing like so

UpdateTimerWeb = new Runnable() {
    @Override
    public void run() {
        webView.reload();
        Web.WebHandler.postDelayed(UpdateTimerWeb, 15 * 60 * 1000); // every 15 mins
    }

};
Web.WebHandler.postDelayed(UpdateTimerWeb, 15 * 60 * 1000); // every 15 mins

Am i supposed to flush it somehow or reinit the webView object or what am i missing?

Daniel Jørgensen
  • 1,183
  • 2
  • 19
  • 42

1 Answers1

0

I have this experience that webView keeps caching, if you want to stop caching use :

webView.settings.setAppCacheEnabled(false)
webView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
webView.settings.javaScriptEnabled = true

you can handle actions on webView by this class in your fragment or activitity :

inner class WebClientCustom : WebViewClient() {

override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
    super.onPageStarted(view, url, favicon)
    //for example progress
    prg.visibility = View.VISIBLE
}

override fun onPageFinished(view: WebView?, url: String?) {
    super.onPageFinished(view, url)
    stopLoading()
}

@TargetApi(Build.VERSION_CODES.M)
override fun onReceivedError(
    view: WebView?,
    request: WebResourceRequest?,
    error: WebResourceError?
) {
    stopLoading()
}

@SuppressWarnings("deprecation")
override fun onReceivedError(
    view: WebView,
    errorCode: Int,
    description: String,
    failingUrl: String
) {
    stopLoading()
}

private fun stopLoading() {
    prg.visibility = View.GONE
    swipeRefreshLayout.isRefreshing = false

}
Bita Mirshafiee
  • 600
  • 8
  • 14