Why does super.onDestroy() in java Android goes on top in destructors?

Vassilis picture Vassilis · Dec 12, 2010 · Viewed 35.7k times · Source

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?

Answer

Cristian picture Cristian · Dec 12, 2010

It really depends on what you want to do in your onDestroy. This is what super.onDestroy does (in that order):

  • Dismiss any dialogs the activity was managing.
  • Close any cursors the activity was managing.
  • Close any open search dialog

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.