WebView 导致 SQLiteDiskIOException
我已经收到 SQLiteDiskIOExceptions 的报告有一段时间了(通过 Flurry/acra)。我无法在本地重现该问题,但这是我最常见的崩溃,在糟糕的一天,每五十次会话中都会发生一次。它们在 Android 2.3.x 下似乎特别频繁。
我在自己的代码中完全没有使用 SQL,但我有多个 WebView 同时运行(两个,外加一个广告 SDK)。这些错误似乎都是由 WebView 通过以下方法之一引起的:
- android.webkit.WebViewDatabase.clearCache
- android.webkit.WebViewDatabase.flushCacheStat
- android.webkit.WebViewDatabase.deleteCookies
- android.webkit.WebViewDatabase.removeCache
(另外收到了一些有关 android.database.sqlite.SQLiteDatabaseCorruptException 的报告,但这些情况极为罕见)。我在自己的代码中注释掉了与清除 WebView 缓存相关的任何内容,但这没有帮助。
有谁知道我可以预防、捕获或更清楚地隔离这些问题的原因吗?例外情况?它们出现的频率太高,不可能只是由 SD 内存损坏引起的。
谢谢!
编辑:按请求源代码:
browser=(WebView)findViewById(R.id.webkit);
browser.setWebViewClient( new CustomWebViewClient(this,browser) );
WebSettings webSettings = browser.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
browser.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
webSettings.setBuiltInZoomControls(true);
browser.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressbarhorizontal.setProgress(progress);
}
});
XML:
<WebView android:id="@+id/webkit" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusable="true" android:nextFocusDown="@+id/bottomview"></WebView>
I've been getting reports of SQLiteDiskIOExceptions for some time now (via Flurry/acra). I haven't been able to reproduce the issue locally, but it's my most frequent crash, occurring up to once in fifty sessions on a bad day. They seem to be particularly frequent under Android 2.3.x.
I make absolutely no use of SQL in my own code, but I have more than one WebView running simultaneously (two, plus an ads SDK). The errors all appear to be caused by a WebView, via one of any of the following methods:
- android.webkit.WebViewDatabase.clearCache
- android.webkit.WebViewDatabase.flushCacheStat
- android.webkit.WebViewDatabase.deleteCookies
- android.webkit.WebViewDatabase.removeCache
(Also received a couple of reports of an android.database.sqlite.SQLiteDatabaseCorruptException , but these are extremely rare). I commented out anything relating to clearing the WebView cache in my own code, but that didn't help.
Does anyone know of any way I could prevent, catch, or more clearly isolate the cause of these exceptions? They're too frequent to just be caused by bad SD memory.
Thanks!
Edit: Source code by request:
browser=(WebView)findViewById(R.id.webkit);
browser.setWebViewClient( new CustomWebViewClient(this,browser) );
WebSettings webSettings = browser.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginsEnabled(true);
browser.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
webSettings.setBuiltInZoomControls(true);
browser.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressbarhorizontal.setProgress(progress);
}
});
XML:
<WebView android:id="@+id/webkit" android:layout_width="fill_parent" android:layout_height="fill_parent" android:focusable="true" android:nextFocusDown="@+id/bottomview"></WebView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 setUncaughtExceptionHandler( ) 以便捕获异常并优雅地处理它。
You may be able to utilize setUncaughtExceptionHandler() in order to catch the exception and gracefully handle it.
我也在努力寻找这些错误的确切根源。我在Google 网上论坛 AdMob 论坛上找到了一个帖子< /a> 这表明它可能与 AdMod SDK 有关。对我来说,这些错误是在我发布最新更新后开始出现的,其中包括将 AdMob SDK 从 v4.1.1 升级到 v4.3.1。您在使用 AdMob 吗?
似乎 AdMob SDK 在某些情况下会脱离 UI 线程来操作其 WebView,我猜这可能会导致各种问题,例如在管理缓存时从不同线程进行并发 SQLite 访问。可能与 Android 中的 SQLiteDiskIOException 有关。可能还值得检查您自己的代码是否不会在 UI 线程之外操作 WebView。
I too am struggling to find the exact source of these errors. I have found a thread on the Google Groups AdMob forum that suggests it might be related to the AdMod SDK. For me, these errors started showing up after I published my latest update, which among other changes included upgrading the AdMob SDK from v4.1.1 to v4.3.1. Are you using AdMob?
Seems that the AdMob SDK in some circumstances manipulates its WebViews off of the UI thread, which I guess could cause various problems, possibly i.e. concurrent SQLite access from different threads when managing the cache. Possibly related to SQLiteDiskIOException in Android. Might also be worthwhile checking that your own code does not manipulate WebViews off of the UI thread.
code.google 网站报告了一个问题。
编辑:如果您准备禁用缓存,异常的频率可能会稍微降低。
There is an issue reported in code.google site.
EDIT : If you are ready to disable the cache, the exception's frequency might decrease a bit.