question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

https://github.com/google/dagger/blob/c1ddd0cfeddaa286e6826d9527a108261f6d4fc3/java/dagger/hilt/android/example/gradle/simple/feature/src/main/java/dagger/hilt/android/example/gradle/simple/feature/FeatureModule.kt#L30

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?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Chang-Ericcommented, Jun 12, 2020

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

0reactions
Zhuindencommented, Jun 12, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hilt (Android): cannot find symbol return ... - Stack Overflow
I got the same error message. My problem was that I had an old/deprecated gradle dependency. Make sure to remove following dpenedency from ......
Read more >
All about Hilt. Get deeper understanding about Hilt.
Hilt is a dependency injection framework for Android that is built on top ... for example, the time/duration between birth and death is...
Read more >
Lucas on Twitter: "@Zhuinden That ActivityRetainedComponent for ...
State inside FeatureModule of Hilt simple example is not persisted across process death · Issue... dagger/java/dagger/hilt/android/example/gradle/simple/feature ...
Read more >
Migrating to Hilt - Dagger
Any method defined directly on the component interface can be moved to either the aggregator interface or one the aggregator extends. Example: Java....
Read more >
Navigation | Android Developers
Navigation Safe Args will no longer cause deprecation warnings in ... and its destination's state after process death and recreation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found