lixplor / android-Q-A

🐞 android related questions and answers
0 stars 0 forks source link

WebView加载错误时, 屏蔽错误页面, 但是wevview会重试3次, 期间错误页面不会消失 #36

Closed lixplor closed 7 years ago

lixplor commented 7 years ago

WebView加载错误时, 屏蔽错误页面, 但是wevview会重试3次, 期间错误页面不会消失

lixplor commented 7 years ago

原因: 确实会重试3次, 错误页面是因为重试了还是错的页面, 而且onReceivedError回调只会在重试3次后回调, 所以不建议用覆盖层, 因为回调太慢, 建议用自定义错误html页面 解决: 自己写一个error.html, 在onReceivedError中记录错误页面的url为lastUrl, 并加载error.html, 此时页面的url为error.html; 所以在重载刷新操作中不用reload(), 而是使用loadUrl(lastUrl), 这样就不会去加载error.html; 如果加载成功, 则lastUrl显示, 否则还会加载error.html并记录lastUrl为lastUrl