skip to Main Content

In my app I have in the mainActivity intent that move mw to the second activity and in the second activity I have also intent that move me to the main activity.
Now when I press the back button in my phone it return’s me to the last activity that i was in but it not the problem, I already know how to disable pressing back button but I
dont want that when I move to another activity the last activity that I was in will keep running I want to stop it from running or either to complete kill it.
Any ideas?

2

Answers


  1. You can achieve this by calling finish() in your second activity after starting MainActivity

        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
        this.finish()
    
    Login or Signup to reply.
  2. Just call:

    finish()

    startActivity(Intent(this@FirstActivity, SecondActivity::class.java))
    finish()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search