0

I am new to Android Development and Kotlin

I notice this function? setContent { } , I want to know what is this block. is it a function !? why it is invoked with curly braces.

the code is bellow

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Text("Hello world!")
        }
    }
}

thanks in advanc

  • yes we can take the lambda function out but we cannot add the name to it – Saad Moh Apr 07 '22 at 13:52
  • 1
    I don't understand what you mean. [`setContent()`](https://developer.android.com/reference/kotlin/androidx/activity/ComponentActivity#(androidx.activity.ComponentActivity).setContent(androidx.compose.runtime.CompositionContext,kotlin.Function0)) is a function that takes a lambda, and this is a trailing lambda syntax like in the linked question. – shriakhilc Apr 07 '22 at 14:19
  • thanks a lot shirakhilc . i got it now ..because it is the only one parameter. – Saad Moh Apr 08 '22 at 01:38

0 Answers0