首页 > 解决方案 > dagger hilt android中的ActivityRetainedComponent @ActivityRetainedScope和ActivityComponent @ActivityScoped有什么区别

问题描述

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

标签: androiddependency-injectiondaggerdagger-hilt

解决方案


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


推荐阅读