Hon Ey Mon Ey
Hon Ey Mon Ey

Reputation: 87

How to GoBack to the previous Activity ? Kotlin ( using a button outside the action bar)

Using a Kotlin code i want to know how to add a button outside the action bar which takes me to the previous Activity on click

Upvotes: 5

Views: 7776

Answers (2)

Amroun
Amroun

Reputation: 465

You can call finish() when button is clicked

button.setOnClickListener {
   finish()
}

Upvotes: 9

Ankit Mehta
Ankit Mehta

Reputation: 4269

Just call onBackPressed(); method from whereever you want to go back to the previous activity/screen. as follows :

btn.setOnClickListener(){
  onBackPressed()
}

Upvotes: 6

Related Questions