All the important info, i.e., business logic that your app depends on should be inside a lifecycle aware component like a ViewModel, not in a remember
ed state inside an @Composable
invocation. This ensures proper disposal of the resources when the app is destroyed, and above everything keeps your data secure.
Have a var initialised and observed inside a viewModel like so
var clipText by mutableStateOf<String?>(null)
fun initialiseModel(context) {
// Do the stuff you want
...
with(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) {
addPrimaryClipChangedListener{
clipText = getText().toStrint()
}
}
}
There may be a cleverer way, but I'm typing this on a mobile device, so can't experiment.
Petition for a Compose Playground app to run composable code on the fly,