0

How to run a Kotlin file from the main_Activity?

Dear SoloLearn I have an database.kt file which an dbhelper class, some functions and so on. How can I let the file (functions) run it automatically on the app startup (how do I declare it in the main_activity.kt file so that it can create my sqlite DB? Thank you for every answer. Kind regards

22nd Apr 2022, 4:33 PM
Julius
1 Antwort
0
import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import com.example.yourpackage.database.setupDatabase // Import your setup function import com.example.yourpackage.database.someOtherFunction // Import other functions as needed class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Call the functions from database.kt setupDatabase(this) // Assuming setupDatabase is a function you want to run someOtherFunction() // Call other functions as needed } }
30th Sep 2023, 7:07 PM
D1M3
D1M3 - avatar