Search code examples
androiddependency-injectiondaggerdagger-hilt

What is difference between ActivityRetainedComponent @ActivityRetainedScope and ActivityComponent @ActivityScoped in dagger hilt android


What is difference between ActivityRetainedComponent @ActivityRetainedScope and ActivityComponent @ActivityScoped in dagger hilt android


Solution

  • Based on the documents. ActivityRetainedComponent lives across configuration changes, so it is created at the first onCreate and last onDestroy, and when you mark your dependencies in ActivityRetainedComponent with @ActivityRetainedScope its guarantees that your object will be a singleton and survive across configuration changes. But ActivityComponent created at onCreate and destroyed at onDestroy. and when you mark your dependencies in ActivityComponent with @ActivityScope its guarantees that your object will be a singleton but ActivityComponent will be destroyed in configuration changes.