New Android developer here, I imagine I’m probably missing something fundamental…
I have a class instance which is not initialised straight away. I pass this to a composable and want to use it after it has been initialised. Something like this:
class MainActivity : AppCompatActivity() {
var camera: USBCamera? = null
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyComposeUI(camera)
}
}
@Composable
fun MyComposeUI(camera: USBCamera?) {
Button(onClick = { camera?.setGain(10) }) {}
}
The problem is this doesn’t work because camera
is always null??
camera
is initialised elsewhere (in a separate thread) and I can make this work by either accessing it using LocalContext
or using lateinit
, but this method is simpler and “feels” like the “correct” way to do it. (Please feel free to suggest better alternatives!)
Not sure if it’s relevant but the USBCmera
class is a java class with calls to a native library