Skip to content

Feature/background memory save - #807

Open
LiangNuoXuan wants to merge 7 commits into
MetaCubeX:mainfrom
LiangNuoXuan:feature/background-memory-save
Open

Feature/background memory save#807
LiangNuoXuan wants to merge 7 commits into
MetaCubeX:mainfrom
LiangNuoXuan:feature/background-memory-save

Conversation

@LiangNuoXuan

Copy link
Copy Markdown

’应用进入后台3秒后自动销毁界面以节省内存‘ 开关
Screenshot_2026-07-26-21-02-10-178_com github me

Add a setting toggle that automatically kills the UI process 3 seconds
after the app goes to background, freeing UI memory while ClashService
keeps running in the :background process.

- UiStore: add autoDestroyUI preference
- AppSettingsDesign: add toggle below "hide from recents"
- MainApplication: observe app visibility and kill UI process
- ApplicationObserver: support multiple visibility listeners (was
  overwritten by Remote.launch, breaking our callback)
ic_baseline_hide was already used by hideAppIcon switch right above;
use ic_baseline_close to avoid duplicate icons on adjacent settings.
@vvb2060

vvb2060 commented Jul 26, 2026

Copy link
Copy Markdown

https://developer.android.com/guide/components/activities/process-lifecycle?hl=zh-cn 建议学习Android应用的生命周期,尤其是缓存进程一节。
Windows不会杀进程,所以主动退出有价值。但Android只要组件生命周期结束,随时会被系统杀掉进程回收内存。那么不主动退出进程就是好的,因为下次打开会更快。

Replace Process.killProcess with finishing all activities and triggering
GC. This avoids bypassing Android lifecycle (Activity.onDestroy, Service
.onDestroy) and resolves LogcatService state leak issues while still
releasing UI memory (View trees, design objects).
Core services (ClashService, TunService, RemoteService) and VPN run in
:background process, unaffected by killing UI process. LogcatService only
starts when user opens logs screen; static 'running' flag resets on new
process launch. Killing UI process is the cleanest way to release all
UI memory (Activities, Views, Design objects, Application singletons).
- Remove redundant ApplicationObserver.attach (Remote.launch already
  calls it); register our listener before Remote.launch so we don't
  miss the first visibility event.
- Remove unused isAppVisible getter.
Keep changes strictly limited to UI process memory management.
@LiangNuoXuan

Copy link
Copy Markdown
Author

https://developer.android.com/guide/components/activities/process-lifecycle?hl=zh-cn 建议学习Android应用的生命周期,尤其是缓存进程一节。 Windows不会杀进程,所以主动退出有价值。但Android只要生命周期组件结束,随时会被系统杀掉进程回收内存。那么不主动退出进程就是好的,因为下次打开会更快。

好的,我写的是开关由用户自己决定

- Add protected activities whitelist to prevent killing during edits
- Add pendingExternalRequest flag to protect VPN authorization flow
- Add polling-based detection (wait when protected, kill when idle)
- Add auto_destroy.log for persistent self-destroy tracking
- Fix type inference for protectedActivities Set<Class<*>
- Complete translations for 6 additional languages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants