Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
129 views
in Technique[技术] by (71.8m points)

java - Difference between code before and after super()

Look at the sample codes below

@Override
protected void onPause() {
    ...some code here...
    super.onPause();
}

and

@Override
protected void onPause() {
    super.onPause();
    ...some code here...
}

When I asked about differences in code, I did not mean about the flow of execution, which is abvious.

So what is the real difference between these codes? When is it advised to use your code before super() call, and when to use your code after super() call? I guess there are situations when this does matter.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You should not place any of your code before super.onPause(), cause this method lets the system do what it needs to do to properly pause your application. Any code you want to execute in the onPause() callback should be placed after the call to super.onPause(). Hope this helps.

Quote from Activities:

Note: Your implementation of these lifecycle methods must always call the superclass implementation before doing any work, as shown in the examples above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...