Leon K
12/12/2020, 5:57 PMAdam Powell
12/12/2020, 6:40 PMAdam Powell
12/12/2020, 6:41 PMLeon K
12/12/2020, 6:48 PMoverride fun onCreateInputView(): View? {
lifecycleRegistry.currentState = Lifecycle.State.CREATED
return ComposeView(applicationContext).apply {
ViewTreeLifecycleOwner.set(this@apply, this@MyInputMethodService)
ViewTreeViewModelStoreOwner.set(this@apply, this@MyInputMethodService)
ViewTreeSavedStateRegistryOwner.set(this@apply, this@MyInputMethodService)
setContent {
Text(text = "heyho")
}
}
}
but then,... how do i properly implement ViewTreeViewModelStoreOwner, and even more confusingly, ViewTreeSavedStateRegistryOwner? There seem to be pretty much 0 docs on thisAdam Powell
12/12/2020, 7:05 PMLeon K
12/12/2020, 7:21 PMonCreateInputView()
before it calls onCreate
on the service blob thinking upside down because of that, i'm getting:
java.lang.IllegalStateException: You can consumeRestoredStateForKey only after super.onCreate of corresponding component
😕Adam Powell
12/12/2020, 7:26 PMAdam Powell
12/12/2020, 7:27 PMAdam Powell
12/12/2020, 7:27 PMLeon K
12/12/2020, 7:36 PMby lazy
, so they're initialized as late as possible, but still the same exception....
any other recommendations as to where to look?Adam Powell
12/12/2020, 7:43 PMAdam Powell
12/12/2020, 7:44 PMLeon K
12/12/2020, 7:46 PMAdam Powell
12/12/2020, 7:52 PMLifecycleRegistry
yourself it only moves to lifecycle states when you tell it to: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:li[…]dx/lifecycle/LifecycleRegistry.java;l=119?q=LifecycleRegistryAdam Powell
12/12/2020, 7:53 PMLeon K
12/12/2020, 7:56 PMCREATED
as soon as i create the instance.... still the same error blob thinking fastLeon K
12/12/2020, 7:57 PMAdam Powell
12/12/2020, 7:58 PMLeon K
12/12/2020, 7:59 PMclass MyInputMethodService : InputMethodService(), LifecycleOwner, ViewModelStoreOwner,
SavedStateRegistryOwner {
private val lifecycleRegistry: LifecycleRegistry by lazy {
LifecycleRegistry(this).apply {
currentState = Lifecycle.State.CREATED
}
}
private val viewModelStore = ViewModelStore()
private val savedStateRegistryController: SavedStateRegistryController by lazy {
SavedStateRegistryController.create(this)
}
override fun getLifecycle(): Lifecycle = lifecycleRegistry
override fun getSavedStateRegistry() = savedStateRegistryController.savedStateRegistry
override fun getViewModelStore() = viewModelStore
override fun onCreateInputView(): View? {
lifecycleRegistry.currentState = Lifecycle.State.CREATED
return ComposeView(applicationContext).apply {
ViewTreeLifecycleOwner.set(this@apply, this@MyInputMethodService)
ViewTreeViewModelStoreOwner.set(this@apply, this@MyInputMethodService)
ViewTreeSavedStateRegistryOwner.set(this@apply, this@MyInputMethodService)
setContent {
Button(onClick = { sendKey() }) {
Text(text = "heyho")
}
}
}
}
// rest of the class
}
Is the minimum relevant bit of code here.... i also don't really get why it wouldn't workAdam Powell
12/12/2020, 8:02 PMLeon K
12/12/2020, 8:22 PMhandstandsam
01/20/2021, 12:02 AMhandstandsam
01/20/2021, 1:57 AM