According to which logic does super.onDestroy();
in destructors goes on top? For example:
protected void onDestroy() { super.onDestroy(); releaseMediaPlayer(); }
and not:
protected void onDestroy() { releaseMediaPlayer(); super.onDestroy(); }
Like in c++, obj-c, pascal, etc?
This is what super. onDestroy does (in that order): Dismiss any dialogs the activity was managing. Close any cursors the activity was managing.
If onDestroy() is called as the result of a configuration change, the system immediately creates a new activity instance and then calls onCreate() on that new instance in the new configuration. The onDestroy() callback should release all resources that have not yet been released by earlier callbacks such as onStop() .
onDestroy( ) is called before the activity is destroyed. The system invokes this callback either because: the activity is finishing (due to the user completely dismissing the activity or due to finish( ) being called on the activity), or.
As specified in the Android documentation, it is not guaranteed that onDestroy() will be called when exiting your application. Instead, you can create a service which will be notified when the Task your activities are running inside is destroyed.
It really depends on what you want to do in your onDestroy
. This is what super.onDestroy does (in that order):
If the logic you put inside onDestroy
has something to do with those three things that android does, then you may have to worry about the order. Otherwise, and in most of the cases, it does not matter.
In the ThreadSample.zip on the Reporting Work Status training, there is a comment in onDestroy()
public void onDestroy() { ... // Must always call the super method at the end. super.onDestroy(); }
So perhaps when using Broadcast Receivers, the super must go at the end.
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