加载大量图片的Android webview使应用程序崩溃

时间:2014-08-22 19:41:16

标签: android webview

我想我期待这种行为,但我不确定,因为我看到PC版本的浏览器在内存限制后卸载和加载图片。事情是我的同事做了一个非常alpha的webapp版本,显示了很多图片,当你向下滚动它时会加载更多。

有一点,当你向下滚动时,它不再加载,它由android关闭或强制关闭(崩溃)。我是否可以在webview上更改某些内容以使其与chrome版本相同,或者我必须告诉我的同事以避免一次性加载所有图片? (可能会将img标记的src属性更改为''会使webview释放它们吗?)。

我已经使用MAT来查看内存问题是否在java端,但是堆只有6mb,但是这个过程在一个设备中是130mb而在另一个设备中是300.

有关如何解决问题的指示?谢谢!

1 个答案:

答案 0 :(得分:1)

你可以做以下事情:

1.通过调用getMemoryClass()在运行时获取可用内存,并根据内存缩放图像或限制图像的数量。

2.在清单中使用largeHeap,以便您的应用在运行时分配更多内存。文档说

Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application. It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use this option consistently or they will have unpredictable results.
Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.

To query the available memory size at runtime, use the methods getMemoryClass() or getLargeMemoryClass().

3.添加

4.通过javascript动态添加删除图像