#6 服务器不能访问后,长时间下来会闪退
This commit is contained in:
@@ -109,6 +109,7 @@ dependencies {
|
||||
|
||||
implementation libs.utilcodex
|
||||
|
||||
implementation libs.dialogx
|
||||
implementation libs.okhttp
|
||||
implementation libs.banner
|
||||
implementation libs.glide
|
||||
|
||||
@@ -9,6 +9,15 @@ author:
|
||||
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
|
||||
|
||||
#### 文件下载
|
||||
|
||||
@@ -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