//创建ViewModel实例 //MyViewModel model = ViewModelProviders.of(this).get(MyViewModel.class); //该方法已弃用 MyViewModel model = new ViewModelProvider(this).get(MyViewModel .class);