viewmodel-savedstate

How to lazily save ViewModel's SavedStateHandle?

大城市里の小女人 提交于 2021-01-27 23:31:03
问题 I have a screen that loads a bunch of requests and collects some data from the user on the same screen and an external WebView. Therefore, I have a ViewModel that contains these complex request objects (+ user input data). I need to persist this data through system-initiated process death, which SavedStateHandle is designed for. But I don't want to persist this data in a database because it is only relevant to the current user experience. I have integrated my ViewModels with Hilt and received

How to dynamically set the bundle from AbstractSavedStateViewModelFactory

丶灬走出姿态 提交于 2020-05-13 13:38:02
问题 My ViewModelFactory : class ViewModelFactory @Inject constructor( private val viewModelMap: MutableMap<Class<out ViewModel>, ViewModelAssistedFactory<out ViewModel>>, owner: SavedStateRegistryOwner, defaultArgs: Bundle? ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @Throws(IllegalStateException::class) @Suppress("UNCHECKED_CAST") override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T { return viewModelMap[modelClass]?.create(handle)

How to dynamically set the bundle from AbstractSavedStateViewModelFactory

余生长醉 提交于 2020-05-13 13:36:05
问题 My ViewModelFactory : class ViewModelFactory @Inject constructor( private val viewModelMap: MutableMap<Class<out ViewModel>, ViewModelAssistedFactory<out ViewModel>>, owner: SavedStateRegistryOwner, defaultArgs: Bundle? ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @Throws(IllegalStateException::class) @Suppress("UNCHECKED_CAST") override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T { return viewModelMap[modelClass]?.create(handle)

Retain EditText with Screen Rotation using Databinding Library

徘徊边缘 提交于 2020-04-05 06:51:07
问题 I have two classes AdminPinActivity.kt and AdminPinActivityPresenter.kt AdminPinActivity.kt: class AdminPinActivity : InjectableAppCompatActivity() { @Inject lateinit var adminPinActivityPresenter: AdminPinActivityPresenter private var input_Pin: String = "" private var input_Confirm_Pin: String = "" companion object { fun createAdminPinActivityIntent(context: Context, profileId: Int, colorRgb: Int): Intent { val intent = Intent(context, AdminPinActivity::class.java) intent.addFlags(Intent