繁体   English   中英

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

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

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

根据文件 ActivityRetainedComponent存在于配置更改中,因此它是在第一次 onCreate 和最后一次 onDestroy 时创建的,并且当您在ActivityRetainedComponent使用@ActivityRetainedScope标记您的依赖项时,它保证您的对象将成为单例并在配置更改后继续存在。 但是ActivityComponentonCreate创建并在onDestroy销毁。 当您在ActivityComponent使用@ActivityScope标记您的依赖项时,它保证您的对象将是单例,但ActivityComponent将在配置更改中被销毁。

@ActivityRetainedScope 将防止配置更改,例如屏幕方向更改、语言更改

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM