If you choose template with Settings creating a project in Androdi Studio 3.4, you will see example app with SettingsActivity
extending AppCompatPreferenceActivity
extending PreferenceActivity
extending ListActivity
extending android.app.Activity
, but not the FragmentActivity
which is necessary for creating a ViewModel
for SettingsActivity
by means of
SettingsViewModel viewModel
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
viewModel = ViewModelProviders.of(this, viewModelFactory).get(SettingsViewModel.class);
}
because of ViewModelProviders.of()
may accept only the FragmentActivity
as a first argument.
Is it possible to create a ViewModel
for AppCompatPreferenceActivity
or it is the next reincarnation of hell with preferences from Google?!