ViewModel新的继承

Activity里面
MyViewModel  myViewModel = new ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication())).get(MyViewModel.class);


Fragment或者viwe里面

ChatFragmentViewModel  chatFragmentViewModel = new ViewModelProvider(chatFragment, new ViewModelProvider.AndroidViewModelFactory(chatFragment.getActivity().getApplication())).get(ChatFragmentViewModel.class);



你可能感兴趣的:(ViewModel新的继承)