After updating navigation
component and lifecycle viewmodel
version to 2.5.0-alpha01 I have got following issue.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.atcc.aewp/com.atcc.aewp.activity.SplashActivity}: java.lang.UnsupportedOperationException: SavedStateViewModelFactory constructed with empty constructor supports only calls to create(modelClass: Class, extras: CreationExtras).
Exception throws when view model is loaded
open class BaseActivity : AppCompatActivity() {
private val appLanguageViewModel: AppLanguageViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
appLanguageViewModel.result.observe(this) {
...
}
}
}
Here is my view model class
class AppLanguageViewModel : ViewModel() {
private val languageLiveData = MutableLiveData<Event<ApplicationLanguage>>()
val result: LiveData<Event<ApplicationLanguage>> = languageLiveData
fun setLanguage(applicationLanguage: ApplicationLanguage) {
if (LanguagePreferences.instance().setLanguage(applicationLanguage.name)) {
languageLiveData.postValue(Event(applicationLanguage))
}
}
}