在LifecycleObserver中使用LiveData

时间:2018-09-05 19:27:49

标签: android android-activity android-livedata

我想在LifecycleObserver中使用LiveData,但是我必须传递一个Activity。我怎么得到这个?

public class ChatFragmentLifecycleObserver implements LifecycleObserver {


    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    void onCreate(LifecycleOwner owner) {


        ChatViewModel chatViewModel = ViewModelProviders.of(*here I need the Activity*).get(ChatViewModel.class);    
}

0 个答案:

没有答案