Skip to main content

Kotlin - Using the MainActivity API in a Different File

·47 words
icysamon
Author
icysamon
Electronics & Creator

Link the file to the same package as MainActivity.

package com.example.name

Create a class and provide a constructor argument of type AppCompatActivity.

class Test(private val appCompatActivity: AppCompatActivity) {}

Create an instance of the class in MainActivity and pass this as the argument.

private val test = Test(this)