1

I was searching, when onDestroy is executed on an android application, so I found that it is executed when the device is low of resources(RAM, CPU) and when finish() is called by the user.

For example, when I press the back button to return from an activity to previous activity, finish() is executed?

Or in what situation is finish() executed?

Thanks.

Cristian Hoyos
  • 1,245
  • 1
  • 9
  • 16

2 Answers2

2

finish is not a callback method like onDestroy, so it won't be called by the system. the developer can call it if he needs it .

ReZa
  • 1,273
  • 2
  • 18
  • 33
0

If you press back button then it will call OnBackPressed method. you can call finish on activity whenever you need to finish the activity.

e.g. activity.finish(). it will complete the Activity lifecycle.

Rakesh
  • 756
  • 1
  • 9
  • 19