refactor(android): call WindowEvent::Destroyed on activity destroy - #1148
Conversation
currently the Rust lifecycle is partially tied to the Android activity lifecycle: - when the activity is created we initialize the event loop: https://github.com/tauri-apps/wry/blob/84b0ec2e35236e0b43150e37b55c7b6d2e5cf7e9/src/android/kotlin/WryActivity.kt#L61 https://github.com/tauri-apps/tao/blob/fda48e80ef0600079666c19146eb01bdfc4dd3c4/src/platform_impl/android/ndk_glue.rs#L196 - on destroy we are not doing anything in particular now, but we should let the app exit the event loop so it can properly restart when the activity gets recreated to reproduce this, open a Tauri app and press the back button - it will destroy the activity, and reopening the app will crash due to some global state trying to reinitialize (like a log plugin initialization or any other global singleton values) closes tauri-apps/tauri#13568
Package Changes Through 48403a1There are 1 changes which include tao with patch Planned Package VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
|
note that Tauri will notice the only window is getting destroyed and automatically exit the event loop; if we want to keep the Rust app alive while the activity is destroyed, we'll need to enhance the lifecycle management on wry and tauri (this includes adding more hooks to detect app restart, currently we only have App::setup to initialize the app window and any other global state, which can't really be reused for app restarts - since you might do some one-off tasks such as initializing the log plugin). |
FabianLars
left a comment
There was a problem hiding this comment.
i think i was never able to reproduce the issue so i didn't test this but it sounds reasonable.
@FabianLars back button to close app and then reopen |
|
yeah, never had problems with that. it worked fine earlier today when i tested the back button default exit behavior in the context of tauri-apps/tauri#14133 (in an emulator) |
|
actually nvm, that test app today was too basic for this |
|
i mean you might not see the crash if you do not initialize the log plugin or any other singleton thingy, you might just notice two entry point calls in the same app instance |
|
yeah idk i think i got that once just now? (versus none with the PR 🤷 ) |
currently the Rust lifecycle is partially tied to the Android activity lifecycle:
tao/src/platform_impl/android/ndk_glue.rs
Line 196 in fda48e8
to reproduce this, open a Tauri app and press the back button - it will destroy the activity, and reopening the app will crash due to some global state trying to reinitialize (like a log plugin initialization or any other global singleton values)
closes tauri-apps/tauri#13568