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

Save restoration doesn't work when Android destroys activity and create it again. #6

Closed
Grouen opened this issue Aug 7, 2021 · 4 comments

Comments

@Grouen
Copy link

Grouen commented Aug 7, 2021

When Android destroys activity Voyager serialize screens and then restore them. But they now are different objects and Voyager uses them as "key" for "navigator.stateHolder.SaveableStateProvider" I think that is why Voyager can't restore state after activity recreation. (Same for tabNavigator.stateHolder.SaveableStateProvider(currentTab))

@adrielcafe
Copy link
Owner

Fixed in 1.0.0-beta04. Updated the docs with instructions.

Thanks again @Grouen !

@Grouen
Copy link
Author

Grouen commented Aug 9, 2021

@adrielcafe Still doesn't work when use transitions. Default CurrentScreen() works fine. I think issue is here:

   Box(modifier) {
        items.forEach {
            key(it.screen) {
                navigator.stateHolder.SaveableStateProvider(it.screen.key) {
                    it.content()
                }
            }
        }
    }

Voyager should use it.screen.key instead of it.screen for key.
By The Way, maybe default key implementation should be unique? Something like View.generateViewId()

@adrielcafe
Copy link
Owner

I was unable to reproduce using transitions with "Don't Keep Activities" enabled. But I've done as you sugested, can you validade with 1.0.0-beta05?

About the key, for that to work the key function must be a property. Since Screen is an interface it can't set the value itself, so every screen would have to do something like override val key = generatedUniqueKey(). This can be avoided by change the Screen to an abstract class, but I don't wan't to do that.

I'll keep looking for options, maybe KSP could help. Feel free to open a new issue about that. And if you have any suggestion will be very welcome :)

@Grouen
Copy link
Author

Grouen commented Aug 10, 2021

I was unable to reproduce using transitions with "Don't Keep Activities" enabled. But I've done as you sugested, can you validade with 1.0.0-beta05?

Issue is fixed, thanks.

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

2 participants