Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3974428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:34:01+00:00 2026-05-20T04:34:01+00:00

In many of Android methods, especially constructors and overridden methods, you should or even

  • 0

In many of Android methods, especially constructors and overridden methods, you should or even must call the parent class method using super(). When you use the Eclipse Source > Override/Implement Methods… you get code from a template with TODO tags like 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);
} 

I do not understand exacly what the superclass does in each case so I always insert my code at the exact location of the //TODO tags. In the example, I would call super() before my code in the constructor and after my code in onDraw().

Can I always rely on these code insertions locations in the generated code? Is there a simple rule/explanation when to call super()?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:34:02+00:00Added an answer on May 20, 2026 at 4:34 am

    This is a good question. Unfortunately, there is no simple rule for this. You need to know what the superclass implementation does. Sometimes (as in View.onDraw()), the superclass implementation does nothing; calling super() is both harmless and unnecessary. In other cases (such as Activity.onCreate()) the superclass implementation performs critical operations that must be executed at some point in the subclass’s processing. Sometimes what happens when you call super() should come before any processing in the subclass, sometimes at other points. Sometimes you want to completely replace the superclass processing with your own, in which case you don’t call super() at all. You have complete freedom to call the superclass version at any point (or even at multiple points) in your subclass’s logic.

    In constructors, the call to a superclass constructor (if present) must be the first thing in the method. If you don’t have one, the compiler automatically inserts a call to the no-argument constructor in the superclass. (If the superclass does not have a no-argument constructor, or if it is not accessible to the subclass, the compiler generates an error.)

    If the documentation doesn’t provide enough information, then you have to look at the source code. The Android code is available here (Gingerbread release). The API code is under core.

    EDIT The code is no longer available at git.kernel.org. Here are two other places where you can browse the code:

    • github.com
    • omapzoom.org

    The main code is in the repository Platform > Frameworks > Base

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use the method profiler to see how many times particular methods
friends, any one guide me what is the purpose of Super class in android
As everybody, I use in my project many libraries and methods. For each method,
I'm using the method given in Android HTML ImageGetter as AsyncTask to load images
I'm using the Android's MediaPlayer class to play some remote resources. I would like
Many Android methods to set layout aspects take an INT as parameter, but the
On many Android devices you can get into a secret settings menu from Phone
I have read many questions about Android, J2ME and RecordStore , but I still
In Android application development, I frequently go through the word CallBack in many places.
As Android developers, we know the important of testing on physical devices--and as many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.