的WebView ReferenceTable溢出(最大值= 512) [英] WebView ReferenceTable overflow (max=512)
问题描述
在我的应用程序,我需要使用的WebView加载许多HTML文件。几个用户操作后,应用程序崩溃。 LogCat中显示了以下错误: ReferenceTable溢出(最大值= 512)
。我还发现了原因坠毁后面。这是在WebKit的一个bug OS 4.1之前
In my app, I need to use webview to load many html files. After several user operations, the app crashes. LogCat shows the following error: ReferenceTable overflow(max=512)
. I also found the reason behind the crash. It was a bug in webkit before os 4.1
我不知道如何避免这种错误。任何解决办法是AP preciated。
I don't know how to avoid this bug. Any workaround is appreciated.
编辑:我只是用mWebview加载本地HTML文件(包含在EPUB文件)。 mWebView.loadChapter(mSpine.get(MINDEX).getHref());
I just use mWebview to load local html file(contained in epub file). mWebView.loadChapter(mSpine.get(mIndex).getHref());
public void loadChapter(String path){
//loadUrl(resourceUri.toString());
Object localObject = "";
try{
InputStream is = this.getmBook().fetchFromZip(path);
localObject = fromStream(is);
is.close();
}catch(Exception e){
e.printStackTrace();
}
String str1 = "file:///" + path;
this.clearCache(true);
loadDataWithBaseURL(str1, (String)localObject, "text/html", "utf-8", null);
}
public String fromStream(InputStream in) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder out = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
out.append(line);
}
return out.toString();
}
我的错误日志如下:
My error log as follows:
同样的问题: Android的web视图JNI错误与使用loadURL
推荐答案
正如你在我的回答看:的 Android的web视图JNI误差使用loadURL当网页加载失败我破坏活动每150次。在你的情况,你就需要计算每一个页面加载和特定数额(如150次)后,销毁,并通过调用该函数重新启动:
As you can see in my answer: Android Webview JNI ERROR with loadUrl I am destroying the Activity every 150 times when a page load fails. In your case you would need to count every page load and after a specific amount (like 150 times) you destroy and restart it by calling the function:
public void KillThisThenStartNewOne(){
Intent intent = new Intent(this.getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.getApplicationContext().startActivity(intent);
//for restarting the Activity
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
由于这是一种变通方法的结果将是,屏幕将显示为空白/黑色也许0.5至1秒,你的活动是从一开始就重新启动,所以你应该保存,如果你想继续读书的实际所有相关信息章等
我希望这会为你工作!
As this is a workaround the result will be that the screen will be blank/black for maybe 0.5 to 1 second and your Activity is restarted from the beginning, so you should save all relevant information if you want to continue reading the actual chapter etc.
I hope that this will work for you!
这篇关于的WebView ReferenceTable溢出(最大值= 512)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!