Home > Software engineering >  Android intent, Same activity is repeating
Android intent, Same activity is repeating

Time:12-29

Hi I am doing android code in Kotlin first time, when I tried to use Intent instead of going to the next page tghe same activity is repeating. I am giving my activity code here

class MainActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        // get reference to button
        val btnStart = findViewById<Button>(R.id.start_button)
        // set on-click listener
        btnStart.setOnClickListener {
            Toast.makeText(this@MainActivity, "You clicked me.", Toast.LENGTH_SHORT).show()
            val intent = Intent(this, QuestionActivity::class.java).apply {
            }
            startActivity(intent)
        }
    }
}

CodePudding user response:

val intent = Intent(this, QuestionActivity::class.java).apply {
            }
            startActivity(intent)

to

val intent = Intent(this, QuestionActivity::class.java)
startActivity(intent)

CodePudding user response:

startActivity(Intent(this, QuestionActivity::class.java))

  • Related