11

在某些网站上,我注意到如果我直接访问内页(即不是通过触摸来自同一网站不同页面的链接),onPageFinished()需要很长时间(即 2 分钟或更长时间!)才能到达。

如果我通过触摸同一网站页面中的链接来加载同一页面,则onPageFinished()始终会在 1-2 秒内到达(相同的 Internet 连接,相同的确切条件)。

在所有情况下,只有一个onPageStarted()而且只有一个onPageFinished()。也就是说,不涉及重定向。

此外,在直接(慢速)和站点内(快速)访问中,整个页面都显示为完整的(视觉上)。只是由于onPageStarted()某种原因拒绝到达(在直接访问中)。

为了更好地理解这个问题,我提供了这样一个页面的例子:

http://mobile.nytimes.com/2013/07/19/world/middleeast/touring-refugee-camp-kerry-sees-mounting-syrian-suffering.html?from=homepage

例如,如果您从网站的主页访问此页面,则访问onPageFinished()速度会更快。

(主页本身,直接访问时,onPageFinished()1-2秒内!)

什么可以解释这种行为?

如何解决这样的问题?

更新 1:查看 LogCat 输出,我注意到慢速(直接)情况的特点是紧接着发生 dalvikvm GC 操作的爆发 onPageStarted()

07-18 21:22:33.876: D/dalvikvm(6298): GC_FOR_MALLOC freed 10371 objects / 495744 bytes in 54ms
07-18 21:22:34.016: D/dalvikvm(6298): GC_FOR_MALLOC freed 808 objects / 50824 bytes in 51ms
07-18 21:22:34.586: D/dalvikvm(6298): GC_FOR_MALLOC freed 1092 objects / 297328 bytes in 72ms
07-18 21:22:34.646: D/dalvikvm(6298): GC_EXTERNAL_ALLOC freed 49 objects / 2296 bytes in 59ms
07-18 21:22:36.526: I/global(6298): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
07-18 21:22:36.626: D/dalvikvm(6298): GC_FOR_MALLOC freed 4687 objects / 513240 bytes in 86ms
07-18 21:22:36.626: I/dalvikvm-heap(6298): Grow heap (frag case) to 3.304MB for 131088-byte allocation
07-18 21:22:36.706: D/dalvikvm(6298): GC_FOR_MALLOC freed 928 objects / 53008 bytes in 69ms
07-18 21:22:36.766: D/dalvikvm(6298): GC_FOR_MALLOC freed 9 objects / 264 bytes in 61ms
07-18 21:22:36.766: I/dalvikvm-heap(6298): Grow heap (frag case) to 3.378MB for 131088-byte allocation
07-18 21:22:36.836: D/dalvikvm(6298): GC_FOR_MALLOC freed 0 objects / 0 bytes in 69ms
07-18 21:22:37.286: D/dalvikvm(6298): GC_FOR_MALLOC freed 547 objects / 98160 bytes in 73ms
07-18 21:22:37.286: I/dalvikvm-heap(6298): Grow heap (frag case) to 3.617MB for 262480-byte allocation
07-18 21:22:37.336: D/dalvikvm(6298): GC_FOR_MALLOC freed 175 objects / 8384 bytes in 46ms
07-18 21:22:37.706: D/dalvikvm(6298): GC_FOR_MALLOC freed 340 objects / 183688 bytes in 78ms
07-18 21:22:37.706: I/dalvikvm-heap(6298): Grow heap (frag case) to 3.994MB for 527244-byte allocation
07-18 21:22:37.776: D/dalvikvm(6298): GC_FOR_MALLOC freed 104 objects / 4560 bytes in 69ms
07-18 21:22:38.006: D/dalvikvm(164): GC_EXPLICIT freed 21550 objects / 1176488 bytes in 137ms
07-18 21:22:38.286: D/dalvikvm(6298): GC_FOR_MALLOC freed 227 objects / 299888 bytes in 50ms
07-18 21:22:38.286: I/dalvikvm-heap(6298): Grow heap (frag case) to 4.135MB for 444555-byte allocation
07-18 21:22:38.326: D/dalvikvm(6298): GC_FOR_MALLOC freed 1 objects / 16 bytes in 41ms
07-18 21:22:38.376: D/dalvikvm(6298): GC_FOR_MALLOC freed 352 objects / 687432 bytes in 36ms
07-18 21:22:38.376: I/dalvikvm-heap(6298): Grow heap (frag case) to 4.330MB for 592732-byte allocation
07-18 21:22:38.416: D/dalvikvm(6298): GC_FOR_MALLOC freed 2 objects / 104 bytes in 44ms
07-18 21:22:38.456: D/dalvikvm(6298): GC_FOR_MALLOC freed 4 objects / 96 bytes in 33ms
07-18 21:22:38.456: I/dalvikvm-heap(6298): Grow heap (frag case) to 4.612MB for 296374-byte allocation
07-18 21:22:38.496: D/dalvikvm(6298): GC_FOR_MALLOC freed 0 objects / 0 bytes in 41ms
07-18 21:22:38.536: D/dalvikvm(6298): GC_FOR_MALLOC freed 162 objects / 599848 bytes in 29ms
07-18 21:22:38.536: I/dalvikvm-heap(6298): Grow heap (frag case) to 5.170MB for 1185448-byte allocation
07-18 21:22:38.576: D/dalvikvm(6298): GC_FOR_MALLOC freed 0 objects / 0 bytes in 40ms
07-18 21:22:38.626: D/dalvikvm(6298): GC_FOR_MALLOC freed 7 objects / 1185616 bytes in 35ms
07-18 21:22:38.626: I/dalvikvm-heap(6298): Grow heap (frag case) to 5.443MB for 878616-byte allocation
07-18 21:22:38.676: D/dalvikvm(6298): GC_FOR_MALLOC freed 0 objects / 0 bytes in 42ms

这是什么意思?这是网站的问题吗?还是在我的代码中?

更新 2:不仅onPageFinished()直接访问 URL 会延迟,而且还会延迟WebChromClient.onProgressChanged()onPageFinished()它总是在 89% 标记处冻结,然后在收到后立即跳到 100% 。奇怪的事情正在发生。为什么?

这可能是网站的故意行为吗?

如果您想回答“是”,为什么在使用不同浏览器(例如 Firefox 或 Chrome)直接访问同一页面时不这样做?

如果这不是该特定网站的故意行为(即我的代码中的错误),为什么其他网站不会发生这种情况?

4

1 回答 1

0

这应该是因为网站必须在内页加载过多的资源。

通过链接访问时加载速度更快的原因是,大多数网页资源是共享的,并且会通过浏览导航被 webview 缓存。

于 2013-07-19T07:41:20.087 回答