0

I am referring the big nerd ranch android book for learning android.

When overriding Activity or Fragment methods, I have come across places where the call to super() is removed, and some places where it is kept as a part of the overriding method.

How can I understand that which methods need the super() and which don't?

And if the super() is to be kept... is it always on the first line? I ask this because while searching for an answer, I came across this

public MyCanvas(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}


@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub      
    super.onDraw(canvas);
}

On a humble note: I have seen the posts

Android Activity which overridden functions must call super.*

and

Locations of super() calls in Android Eclipse Plugin generated code reliable?

but it didn't clear my doubts. So I hope I am not breaking any rules by posting this question.

Community
  • 1
  • 1
Jeet Parekh
  • 740
  • 2
  • 8
  • 25
  • http://stackoverflow.com/a/10843452 – Sree Dec 14 '15 at 08:04
  • you should spend sometime on override method on Java first, for more understanding about how/when/where/why super() method works – Linh Nguyen Dec 14 '15 at 08:24
  • 1
    @LinhNguyen I have worked with java for 2 years, I am well aware how `super()` works. But in Android, sometimes `super()` is used and sometimes it isn't... and that's what the question is about – Jeet Parekh Dec 14 '15 at 08:48
  • you will come to the answer if you get the difference between call the super() method at the first line and the last – Linh Nguyen Dec 14 '15 at 08:57

0 Answers0