Simple question: can you be sure that finish()
will call onDestroy()
? I haven't found any confirmation on this.
Third, finish() does not call onDestroy() . You can tell that by reading the source code.
onDestroy() should be called at the end because then your code will be called before it is destroyed.
On Clicking the back button from the New Activity, the finish() method is called and the activity destroys and returns to the home screen.
Android will generally call onPause() if you call finish() at some point during your Activity's lifecycle unless you call finish() in your onCreate() .
Simple question: can you be sure that finish() will call onDestroy()?
First, this answer assumes that you are referring to Android's Activity
class and its finish()
method and onDestroy()
lifecycle method.
Second, it depends upon your definition of "sure":
Your process could be terminated in between finish()
and onDestroy()
, for reasons independent of whatever is triggering the call to finish()
A device manufacturer or ROM modder could introduce some screwy change that would break the connection between finish()
and onDestroy()
The battery could go dead in between finish()
and onDestroy()
Etc.
Third, finish()
does not call onDestroy()
. You can tell that by reading the source code. finish()
usually triggers a call to onDestroy()
.
Generally speaking, finish()
will eventually result in onDestroy()
being called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With