在 WebView 中捕获 Flash 内存不足错误? [英] Catch Flash out-of-memory error in WebView?

查看:17
本文介绍了在 WebView 中捕获 Flash 内存不足错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将某些 .swf 文件加载到 WebView 时,在 flash 文件开始显示后的一瞬间,我的应用程序因 Signal 11 故障而关闭.没有抛出我可以看到的异常.此处为 LogCat 转储示例.

When loading certain .swf files into a WebView, a split second after the flash file begins to be displayed, my app closes with a Signal 11 fault. No exception is thrown that I can see. Example LogCat dump here.

将相同的 .swf 文件加载到常用的 Android 浏览器中时,会显示一个错误图标,而不是关闭.触摸它会打开一个弹出窗口,说明:Adobe Flash;内存不足".

When loading the same .swf files into the stock Android browser, instead of closing, an error icon is displayed. Touching it opens a pop-up stating: "Adobe Flash; Insufficient Memory".

我的问题是:有什么方法可以在 SIGSEGV 发生之前捕获内存不足错误——防止任务被终止——就像股票浏览器所做的那样?任何帮助将不胜感激!

My question is: Is there any way to catch the Insufficient Memory error before the SIGSEGV occurs -- preventing the task from being terminated -- as is done by the stock browser? Any help would be greatly appreciated!

注意:我正在 Android 2.2 下使用 HTC 版本的 Flash 插件进行测试,但似乎在其他非 HTC 设备上也会出现同样的问题.我正在将 swf 文件直接加载到 WebView 中,使用:

Note: I'm testing under Android 2.2 with the HTC version of the Flash plugin, but it appears that the same sort of issues occur on other, non-HTC devices. I'm loading the swf file into the WebView directly, using:

webView.loadUrl("http://whatever.com/bla.swf");

(启用插件和 JavaScript).它在大多数情况下都能完美运行——只有少数文件会导致问题.我尝试了各种减少内存的建议(例如清除 WebView 缓存),但均未成功.

(with plugins and JavaScript enabled). It works perfectly in most cases -- only a few files cause problems. I've tried various suggestions for reducing memory (such as clearing the WebView caches) without success.

推荐答案

如果系统告诉您内存不足,则另一种解决方案可能是使用后台任务或服务来监控设备上的内存使用情况, 杀死 flash 活动.

An alternative solution could be to use a background task or service to monitor the memory usage on the device, if the system tells you that you're on low memory, kill the flash activity.

要知道您是否内存不足,您可以使用以下代码:

To know if you are on low memory you can use this code:

ActivityManager activityManager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); 
activityManager.getMemoryInfo(memoryInfo);

boolean onLowMemory = memoryInfo.lowMemory;

或者您可以使用 memoryInfo.availMem 检查可用内存,如果它太低(接近 memoryInfo.threshold)在异常之前终止您的活动.

Or you can check the available memory using memoryInfo.availMem, if it's too low (close to memoryInfo.threshold) kill your activity before the exception.

这篇关于在 WebView 中捕获 Flash 内存不足错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆