<powerbell> 优化 ChargeMailNotify 开关联动逻辑

1. SettingsActivity 充电邮件通知开关
   - 开启时:先 stopService 再 startService 重启 ControlCenterService
   - 关闭时:停止 RemindThread 并关闭悬浮窗

2. ControlCenterService 服务销毁
   - onDestroy 中关闭 ChargeMailNotifyFloatWindow 悬浮窗
   - 资源释放顺序:前台服务 → 线程 → 悬浮窗 → 广播接收器 → Handler → 通知
This commit is contained in:
MiMo
2026-07-18 05:21:48 +08:00
parent 184ea4fd71
commit 97f42054d2
2 changed files with 10 additions and 3 deletions
@@ -22,6 +22,7 @@ import cc.winboll.studio.powerbell.models.ThoughtfulServiceBean;
import cc.winboll.studio.powerbell.utils.ChargeMailNotifyHelper;
import cc.winboll.studio.powerbell.utils.ChargeMailNotifyFloatWindow;
import cc.winboll.studio.powerbell.threads.RemindThread;
import cc.winboll.studio.powerbell.services.ControlCenterService;
import android.widget.Switch;
import java.lang.reflect.Field;
@@ -262,8 +263,13 @@ public class SettingsActivity extends WinBoLLActivity implements IWinBoLLActivit
LogUtils.d(TAG, "onChargeMailNotifySwitchChanged: 充电邮件通知开关状态=" + isChecked);
ChargeMailNotifyHelper.setEnabled(this, isChecked);
updateSMTPConfigViewEnabled(isChecked);
// 关闭时停止RemindThread并关闭悬浮窗
if (!isChecked) {
if (isChecked) {
// 开启时重启ControlCenterService
LogUtils.d(TAG, "onChargeMailNotifySwitchChanged: 开启充电邮件通知,重启ControlCenterService");
stopService(new Intent(this, ControlCenterService.class));
startService(new Intent(this, ControlCenterService.class));
} else {
// 关闭时停止RemindThread并关闭悬浮窗
LogUtils.d(TAG, "onChargeMailNotifySwitchChanged: 关闭充电邮件通知,停止RemindThread");
RemindThread.stopRemindThread();
LogUtils.d(TAG, "onChargeMailNotifySwitchChanged: 关闭充电邮件通知悬浮窗");
@@ -95,9 +95,10 @@ public class ControlCenterService extends Service {
LogUtils.d(TAG, "onDestroy() 执行:服务销毁流程启动");
super.onDestroy();
// 资源释放顺序:前台服务 → 线程 → 广播接收器 → Handler → 通知 → 引用(避免内存泄漏)
// 资源释放顺序:前台服务 → 线程 → 悬浮窗 → 广播接收器 → Handler → 通知 → 引用(避免内存泄漏)
stopForegroundService();
RemindThread.stopRemindThread();
ChargeMailNotifyFloatWindow.dismissWindow();
releaseBroadcastReceiver();
destroyHandler();
releaseNotificationResource();