[FIX] 修復整點閒置重啟時觸發兩次的問題
1. 於 HomeActivity.java 中引進 SharedPreferences 持久化機制,比對當前日期與時間 Slot(如 yyyy-MM-dd HH:mm),避免同一分鐘內或 App 被 kill 掉重啟後重複觸發 RestartAPP2 背景等待執行緒。 2. 於 FontendActivity.java 中同步套用 SharedPreferences 限制邏輯,確保在首頁或購物頁面皆能共享同個重啟記錄,防止發生 90 秒後二次重啟的 Bug。
This commit is contained in:
parent
ee8143032a
commit
465125f614
@ -143,8 +143,18 @@ public class HomeActivity extends AppCompatActivityAbstract {
|
||||
}
|
||||
if (timeByM.equals("23:59") || timeByM.equals("04:00") || timeByM.equals("08:00")
|
||||
|| timeByM.equals("12:00") || timeByM.equals("16:00") || timeByM.equals("20:00")) {
|
||||
getLogs().info("當前時間:" + timeByM + ",符合條件,啟動 RestartAPP2 (硬重啟等待模式)...");
|
||||
new RestartAPP2(this).start();
|
||||
android.content.SharedPreferences prefs = getSharedPreferences("AppRestartPrefs", Context.MODE_PRIVATE);
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
|
||||
String currentSlot = today + " " + timeByM;
|
||||
String lastRestartSlot = prefs.getString("last_restart_slot", "");
|
||||
|
||||
if (!currentSlot.equals(lastRestartSlot)) {
|
||||
prefs.edit().putString("last_restart_slot", currentSlot).commit();
|
||||
getLogs().info("當前時間:" + timeByM + ",符合條件,啟動 RestartAPP2 (硬重啟等待模式)...");
|
||||
new RestartAPP2(this).start();
|
||||
} else {
|
||||
getLogs().debug("當前時間時段 " + currentSlot + " 已執行過重啟,跳過重複啟動");
|
||||
}
|
||||
}
|
||||
|
||||
//每半小時主動連線下位機一次
|
||||
|
||||
@ -247,11 +247,19 @@ public class FontendActivity extends AppCompatActivityAbstract {
|
||||
// 【第一層】定時重啟:到了整點就啟動等待模式(RestartAPP2 自己會等閒置 >= 90 秒才真重啟)
|
||||
if (timeByM.equals("04:00") || timeByM.equals("08:00") || timeByM.equals("12:00")
|
||||
|| timeByM.equals("16:00") || timeByM.equals("20:00") || timeByM.equals("23:59")) {
|
||||
long idle = MyApp.getInstance().getIdleSeconds();
|
||||
getLogs().info("定時重啟觸發:" + timeByM + ",目前閒置 " + idle + " 秒,啟動等待模式...");
|
||||
// 無論有沒有人在用,都啟動 RestartAPP2
|
||||
// RestartAPP2 會每 5 秒檢查一次,直到閒置 >= 90 秒才真正重啟(最多等 10 分鐘)
|
||||
new RestartAPP2(this).start();
|
||||
android.content.SharedPreferences prefs = getSharedPreferences("AppRestartPrefs", Context.MODE_PRIVATE);
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
|
||||
String currentSlot = today + " " + timeByM;
|
||||
String lastRestartSlot = prefs.getString("last_restart_slot", "");
|
||||
|
||||
if (!currentSlot.equals(lastRestartSlot)) {
|
||||
prefs.edit().putString("last_restart_slot", currentSlot).commit();
|
||||
long idle = MyApp.getInstance().getIdleSeconds();
|
||||
getLogs().info("定時重啟觸發:" + timeByM + ",目前閒置 " + idle + " 秒,啟動等待模式...");
|
||||
new RestartAPP2(this).start();
|
||||
} else {
|
||||
getLogs().debug("當前時間時段 " + currentSlot + " 已執行過重啟,跳過重複啟動");
|
||||
}
|
||||
}
|
||||
|
||||
// 【第二層】閒置深度刷新:任何時間閒置超過 30 分鐘就重啟 (暫時關閉,改依賴定時重啟)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user