android dagger hilt 中的ActivityRetainedComponent @ActivityRetainedScope 和ActivityComponent @ActivityScoped 有什么区别

abh*_*era 5 android dependency-injection dagger dagger-hilt

android dagger hilt 中的ActivityRetainedComponent @ActivityRetainedScope 和ActivityComponent @ActivityScoped 有什么区别

小智 12

根据文件ActivityRetainedComponent存在于配置更改中,因此它是在第一个 onCreate 和最后一个 onDestroy 时创建的,当您标记依赖项时,它ActivityRetainedComponent保证@ActivityRetainedScope您的对象将是单例并在配置更改中生存。但ActivityComponent创建于onCreate并销毁于onDestroy。当您ActivityComponent@ActivityScope它来标记依赖项时,您的对象将是单例,但ActivityComponent会在配置更改中被破坏。