theWalker
theWalker

Reputation: 2020

Android: where in code super class must be calling

What is right?

@Override
protected void onPause() {
    // myCode
    super.onPause();
}

or

@Override
protected void onPause() {
    super.onPause();
    // myCode
}

Upvotes: 1

Views: 73

Answers (1)

aioobe
aioobe

Reputation: 420951

This entirely depends on whether you want your code to be run before or after the super implementation. There's no right or wrong.

See these two examples:

// prepend instructions to onPause
@Override
protected void onPause() {
    Log.debug("About to pause application...");
    super.onPause();
}

vs

// append instructions to onPause
@Override
protected void onPause() {
    super.onPause();
    Log.debug("Just paused the application...");
}

In the specific case of onPause however, you should always call super.onPause first. See Pausing and Resuming an Activity.

Upvotes: 2

Related Questions