ViewModule AndroidViewModule

If you need to use context inside your viewmodel you should use AndroidViewModel, because it contains the application context (to retrieve the context call getApplication() ), otherwise use regular ViewModel.E如果您需要在viewmodel中使用上下文,则应使用AndroidViewModel,因为它包含应用程序上下文(以检索上下文调用getApplication()),否则使用常规ViewModel。

AndroidViewModel has Application Context. We all know Having static Context instance is Evil!(can cause Memory Leak!!)

But, Having static Application instance is not bad than you think

Because, there is only one Application instance in our running application.

So, using & having Application instance in specific class is not problem generally.

But, if Application instance reference them, it is problem because of reference cycle problem.

分类: 未分类




电子邮件地址不会被公开。 必填项已用*标注