How to pass activity’s function to compose

You can pass it as a method reference

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        setContent {
            Main(activityFunWithParam = ::activityFunWithParam)

    fun activityFunWithParam(param: Int) {
        Toast.makeText(this, param.toString(), Toast.LENGTH_SHORT).show()

fun Main(
        activityFunWithParam: (Int) -> Unit
) {
    Text(text = "Test")

In your example, method name itself is not a function. See

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top