Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an AndroidApp::set_save_state() API and correctly restore state for multiple Resumes during process lifetime #34

Open
rib opened this issue Oct 11, 2022 · 0 comments

Comments

@rib
Copy link
Collaborator

rib commented Oct 11, 2022

Currently state saving is based on the android_native_app_glue design whereby there is a saved_state, malloc() allocation and saved_state_size that are only allowed to be modified during MainEvent::SaveState.

This state is initialized during onCreate but it is cleared after each Resume event.

This means that if there are multiple Resume events (can happen when switching Android applications) then later Resume events may be passed no state (and even the first Resume may get no state if no state was passed to onCreate.

The current design is also awkward from the POV that we are tracking a malloc() allocation whose ownership is context sensitive. It is owned by the app when passed to onCreate and it is owned by the ANativeActivity when it is set during MainEvent::SaveState.

Instead of tracking this malloc() allocation state we should simply track a save_state: Vec<u8> that can be updated and queried at any time. When ANativeActivity needs to get this state via onSaveInstanceState then we can simply copy the state into a transient malloc() allocation.

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

No branches or pull requests

1 participant