Should we name the superclass before or after the execution of some code

Android Studio 0.4.6

Hello,

I have a piece of code here. And they often confuse me if super should be the first line of execution or the last. I usually make this the first call so that the default properties can be set in the parent class. However, I was looking at some kind of code that does this before. I'm just wondering, doesn't it matter?

  @Override
    protected void onDestroy() {
        mBroadCastMgr.unregisterReceiver(receiver); 
        super.onDestroy();
    }
+4
source share
6 answers

As in the docs:

onDestroy () = This callback is called before the action is destroyed by the system.

Illustration example:

/** Called just before the activity is destroyed. */
   @Override
   public void onDestroy() {
      super.onDestroy();
      Log.d(msg, "The onDestroy() event");
   }

Popularly mentioned by @Cristian (don't know where) -

, onDestroy. , super.onDestroy ( ):

1) , .

2) , .

3) .

,

" , onDestroy, - , , , , . , ."

+4

, -, , -, . , - - - -

onDestroy, , , super.onDestory

onSaveInstanceState, , super.onSaveInstanceState, ( , )

+2

, :

@Override
protected void onDestroy() {
    try {
        mBroadCastMgr.unregisterReceiver(receiver);
    } finally {
        super.onDestroy();
    }
}

, , ( javadoc) .

+2

, , , - . , , .

+1

/ , .

/ , :

@Override
protected void onInit() {
    super.onInit();
}
+1

@ReeCube, - , , -, . , , - . , . , -, . , . , , , , ( ), , , .

0
source

Source: https://habr.com/ru/post/1529382/


All Articles