#6 服务器不能访问后,长时间下来会闪退

This commit is contained in:
Zhanghu
2026-03-16 14:19:45 +08:00
parent fcfc964fb6
commit 5f1757fed4
3 changed files with 24 additions and 13 deletions

View File

@@ -109,6 +109,7 @@ dependencies {
implementation libs.utilcodex implementation libs.utilcodex
implementation libs.dialogx
implementation libs.okhttp implementation libs.okhttp
implementation libs.banner implementation libs.banner
implementation libs.glide implementation libs.glide

View File

@@ -9,6 +9,15 @@ author:
2. $ {VERSION_CODE} (去掉空格),会自动替换实际修订号,比如 1.1.4.$ {VERSION_CODE} 2. $ {VERSION_CODE} (去掉空格),会自动替换实际修订号,比如 1.1.4.$ {VERSION_CODE}
--> -->
### [1.1.1.${VERSION_CODE}] - 2026.3.16
#### 文件下载
* [dashboardclient_1.1.1.apk](dashboardclient_1.1.1.apk)
#### 更新记录
* 修正达到重试加载链接上限之后闪退的问题
### [1.1.0.32] - 2026.3.13 ### [1.1.0.32] - 2026.3.13
#### 文件下载 #### 文件下载

View File

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