diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainMoGoApplication.java b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainMoGoApplication.java index 7e5c962fbd..889febb1a4 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainMoGoApplication.java +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/main/MainMoGoApplication.java @@ -43,6 +43,7 @@ import com.zhjt.mogo_core_function_devatools.monitor.db.CpuInfo; import com.zhjt.mogo_core_function_devatools.monitor.db.MemInfo; import com.zhjt.mogo_core_function_devatools.monitor.db.MonitorDb; +import java.io.File; import java.lang.reflect.Field; import java.text.SimpleDateFormat; import java.util.Date; @@ -101,15 +102,25 @@ public abstract class MainMoGoApplication extends AbsMogoApplication { new Thread(() -> { String lastLaunchTimeStr = SPUtils.getInstance().getString("last_launch", ""); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + Date currDate = new Date(System.currentTimeMillis()); + String currTimeStr = format.format(currDate); if (lastLaunchTimeStr != null && !lastLaunchTimeStr.isEmpty()) { - Date currDate = new Date(System.currentTimeMillis()); - String currTimeStr = format.format(currDate); boolean isSameDay = currTimeStr.equals(lastLaunchTimeStr); // 超过一天需要清除消息盒子中的数据,并把时间戳存入SP if (!isSameDay) { - this.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME); + File file = this.getDatabasePath(MsgBoxDb.INTERNAL_DB_NAME); + if (file != null && file.exists()) { + this.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME); + } SPUtils.getInstance().put("last_launch", currTimeStr); } + } else { + // 首次使用App或中途仅删除sp文件 + File file = this.getDatabasePath(MsgBoxDb.INTERNAL_DB_NAME); + if (file != null && file.exists()) { + this.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME); + } + SPUtils.getInstance().put("last_launch", currTimeStr); } }).start(); }