I am opening two activities at the same time. One is MainActivity and another one is CustomActivity with the button id returnbutton. I want to close the CustomActivity only by clicking the button and make MainActivity running. I use the code of this.finish() on button clicking but when I click it, my whole app finishes. Someone please help me to finish the CustomActivity only.This is my code
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val intent = Intent(application, CustomActivity::class.java)
startActivity(intent)
val button : Button = findViewById(R.id.returnButton)
button.setOnClickListener {
this.finish()
}