我在每个屏幕上使用Koin和Fragment + ViewModel。在我的HomeFragment中,我有一个带有post的列表。class HomeFragment : Fragment() {
//when user select post I set that value to LeadView
但是,我需要在片段之间传递一个类对象。我在多个片段之间实现了一个sharedViewModel,但是set值总是给出null。我知道这是因为我没有将活动上下文传递给片段中的视图模型的初始化。我正在使用ModelFactory来创建视图模型的实例,但是我无法找到给出'applicationActivity()‘的方法。constructor(private val repository: MyRepository): View