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

State inside FeatureModule of Hilt simple example is not persisted across process death #1866

Open
Zhuinden opened this issue May 30, 2020 · 5 comments

Comments

@Zhuinden
Copy link

Zhuinden commented May 30, 2020

Not persisting such state can cause unexpected behaviors and bugs, especially if this is used to share state between screens.


This raises following questions:

1.) if ViewModel is used under the hood for ActivityRetainedComponent, then how do I intercept onCleared() in my custom classes?

2.) if ViewModel is used under the hood for ActivityRetainedComponent, then how do I get a SavedStateHandle into my custom classes?

3.) if ViewModel is not used for ActivityRetainedComponent, how do I get a reference to the SavedStateRegistry into my custom classes?


Overall, the question boils down to:

  • how to save state inside an ActivityRetainedComponent across process death?
@Chang-Eric
Copy link
Member

Just FYI, we're going to come back to this issue about Hilt after the official launch. Thanks for filing it though and sorry for the wait!

@Zhuinden
Copy link
Author

Zhuinden commented Jun 2, 2020

It's fine, thanks for the reply and will look forward to it 🙂

@Chang-Eric
Copy link
Member

Coming back to this, we have plans to make a SavedStateHandle binding available in the ActivityRetainedComponent. You're right though that there is currently no way to handle process death in the ActivityRetainedComponent right now unfortunately.

@Chang-Eric Chang-Eric self-assigned this Jun 12, 2020
@Zhuinden
Copy link
Author

we have plans to make a SavedStateHandle binding available in the ActivityRetainedComponent.

That would solve it!

BTW, is ActivityRetainedComponent deps inherited into @ViewModelInject annotated ViewModels?

@Chang-Eric
Copy link
Member

Yes, @ViewModelInject classes inject themselves from the ActivityRetainedComponent. This is true regardless of what ViewModelOwner is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants