0

Can I change what that button does. I tried just using it but when the user changes something and goes back, the changes aren't applied

Image

3 Answers3

0

It's very easy, just override onBackPress of your activity. Check documentation for more info - https://developer.android.com/reference/android/app/Activity#onBackPressed()

Alex Grebennikov
  • 170
  • 5
  • 11
0

Did you search for it?

Android - How To Override the "Back" button so it doesn't Finish() my Activity?

you can override onBackPressed() method in your activity

Erfan
  • 83
  • 4
  • 9
0

Try this simple code:

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

   override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    override fun onBackPressed() {
      //  super.onBackPressed()
        Toast.makeText(this,"Back Pressed",Toast.LENGTH_LONG).show()
    }

}
MMG
  • 3,226
  • 5
  • 16
  • 43