#6 服务器不能访问后,长时间下来会闪退
This commit is contained in:
@@ -25,6 +25,9 @@ import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.kongzue.dialogx.dialogs.TipDialog;
|
||||
import com.kongzue.dialogx.dialogs.WaitDialog;
|
||||
|
||||
import cn.ykbox.dashboard.alarm.PowerAlarmManager;
|
||||
import cn.ykbox.dashboard.databinding.ActivityBuildingDashboardBinding;
|
||||
import cn.ykbox.dashboard.perferences.PreferenceConfiguration;
|
||||
@@ -32,14 +35,11 @@ import cn.ykbox.dashboard.serial.SerialPortDetector;
|
||||
|
||||
public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
private final static String TAG = "DashboardActivity";
|
||||
|
||||
private static final boolean AUTO_HIDE = true;
|
||||
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
|
||||
|
||||
private Context mContext;
|
||||
private String mainUrl;
|
||||
private int retryCount = 0;
|
||||
private static final int MAX_RETRY = 99; // 最大重试次数
|
||||
private long retryCount = 0;
|
||||
private static final long MAX_RETRY = Long.MAX_VALUE; // 最大重试次数
|
||||
private static final int RETRY_DELAY = 60000; // 1分钟 = 60000毫秒
|
||||
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener;
|
||||
@@ -237,7 +237,9 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
} else {
|
||||
Log.e("WebView", "重试次数已达上限,加载失败");
|
||||
// 这里可以显示错误页面或提示用户
|
||||
showToast("网页加载失败,请检查网络连接");
|
||||
runOnUiThread(() -> {
|
||||
TipDialog.show("重新加载失败次数已达上限,请联系管理员。", WaitDialog.TYPE.ERROR, -1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,13 +304,17 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
webSettings.setBuiltInZoomControls(false);
|
||||
|
||||
binding.webview.setInitialScale(100);
|
||||
|
||||
binding.webview.setWebViewClient(new WebViewClient() {
|
||||
private boolean hasError = false;
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
hasError = false;
|
||||
|
||||
if(retryCount <= 0)
|
||||
WaitDialog.show("正在加载...");
|
||||
else
|
||||
WaitDialog.show( "第 " + retryCount + " 次重试... ");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -337,6 +343,7 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
super.onPageFinished(view, url);
|
||||
if (!hasError) {
|
||||
retryCount = 0;
|
||||
WaitDialog.dismiss();
|
||||
Log.d("WebView", "加载OK");
|
||||
}
|
||||
}
|
||||
@@ -368,10 +375,4 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
settingsLauncher.launch(intent);
|
||||
}
|
||||
|
||||
private void showToast(String message) {
|
||||
runOnUiThread(() -> Toast.makeText(mContext,
|
||||
message,
|
||||
Toast.LENGTH_SHORT).show());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user