super.onBackPressed() or Finish()?

Asked

Viewed 2,014 times

1

What is the difference between the methods? in the case of super.onBackPressed() can only be used within the right onBackPressed() method?

  • 1

    What context and exactly do you want to do?

1 answer

2


When you call super.onBackPressed() at all times within the onBackPressed() means that you are assuming the default behavior of the button back of the device, i.e., "back up" that terminates the activity.

inserir a descrição da imagem aqui

Image Source

The idea of making override of function onBackPressed() is you can define the behavior you want when the user clicks the button back device. If you call super.onBackPressed() you’re maintaining the button’s behavior back, even so you can add other behaviors like storing variables before closing the activity.

The finish() (also) serves to finish the activity you are running at any time without using the button back. You can even use another button in your app to finish the activity.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.