// Import necessary packages
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
// Define the main activity class
class MainActivity : AppCompatActivity() {
// Override the onCreate method
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) // Set the content view to the layout resource
// Find the button by its ID in the layout
val startButton: Button = findViewById(R.id.btnStart)
// Set an onClickListener for the button
startButton.setOnClickListener(View.OnClickListener {
// Create an Intent to specify the target activity
val intent = Intent(this@MainActivity, TargetActivity::class.java)
// Optionally, add data to the Intent using putExtra methods
intent.putExtra("key", "value")
// Start the target activity using the created Intent
startActivity(intent)
})
}
}