0
我在webview中加载url,但如果wifi关闭,我打开WIFI设置。当用户打开wifi并回到应用程序时刷新webview
现在我想当用户打开wifi并回来webview应该刷新它自己再次加载网址。
只有当网页由于任何原因未加载时,是否有方法在5秒后连续刷新它。
我在webview中加载url,但如果wifi关闭,我打开WIFI设置。当用户打开wifi并回到应用程序时刷新webview
现在我想当用户打开wifi并回来webview应该刷新它自己再次加载网址。
只有当网页由于任何原因未加载时,是否有方法在5秒后连续刷新它。
您可以在的onResume()方法来检查用户是否已经与无线网络连接返回,然后调用他的方法
@Override
public void onResume() {
super.onResume();
if(connected){
webview.loadUrl("your url");
}
}
对于刷新它每隔5秒就可以使用计时器
Handler ha=new Handler();
ha.postDelayed(new Runnable() {
@Override
public void run() {
webview.loadUrl("your url");
ha.postDelayed(this, 5000);
}
}, 5000);
我刚刚写过if条件中的连接。您将不得不使用您检查连接的方式。
wv.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
你可以保持一个布尔标志,以检查是否网址加载错误和onREceived错误改变它的值。并且只有在前一次出现错误时才加载新的网址。
每隔5秒加载一次,仅当无法加载页面时才显示。 – Yawar
loadResults(“链接”)onResume() – Mrinmoy