Syntax question regarding methods


Last Updated:

  1. keratos

    keratos New Member This Topic's Starter

    Joined:
    Sep 23, 2010
    Messages:
    4
    Likes Received:
    0
    Can someone explain this to me please:

    Activity.getWindow().setFeatureInt(Window.FEATURE_ PROGRESS, level).

    My understanding:
    Activity is a class.
    getWindow() is a public method of the Activity
    setFeatureInt is a public method of the Window class.

    So, in Android, is this on-the-fly binding, in that at compile time the target of the setFeatureInt is not known. The target can only be resolved at run time using the return value from getWindow(). Is this a feature of Android or Java? In C, I would expect the analogous syntax to be:

    setFeatureInt(Activity.getWindow(),Window.FEATURE_ PROGRESS, level);

    where the prototype for setFeatureInt would be:

    void setFeatureInt(struct *Window; int mFeature; int mLevel);

    I dont see any difference really, other than the way the statement is constructed, inline (Java) as apposed to parameterised ("C")
     

    Advertisement
  2. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
    Actually the target is known.

    Activity.getWindow() returns a Window object from the Activity.
    .setFeatureInt(Window.FEATURE_PROGRESS, level) is a public method of Window.

    You don't have to store the Window from Activity.getWindow() first, before calling .setFeatureInt().
     
  3. keratos

    keratos New Member This Topic's Starter

    Joined:
    Sep 23, 2010
    Messages:
    4
    Likes Received:
    0
    thanks for the reply
    I feel we are on the same page,
    but remember.,...
    my question was seeking confirmation that AT COMPILE TIME the WINDOW handle is not known. Activity.GetWindow() is a runtime resolution in that at the point of compilaton, the window could absolutely not be known. Its kind of like loose linking in windoze, where the address (the window handle) is resolved only AFTER the call to Activity.GetWindow().
    What I am seeking is simply confirmation that the JAVA construct:

    Activity.GetWindow().SetFeature....

    is the same as

    SetFeature(GetWindow...)

    where , in "C" the prototype

    setFeatureInt(Activity.getWindow(),Window.FEATURE_ PROGRESS, level)

    is the same !! ??
     
  4. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
    java assumes that Activity.getWindow() returns a valid Window object. If not, it returns NULL and your app crashes. So the window handle is not known until the call is made.



    Hope I understood your question right this time.
     
  5. keratos

    keratos New Member This Topic's Starter

    Joined:
    Sep 23, 2010
    Messages:
    4
    Likes Received:
    0
    YES thank you.
    I'm being slightly pedantic.
    We are on the same page.

    perhaps its a difference in age, I'm 45 and an embedded systems programmer consultant, trying to retire now though!!.

    In my day this was called "weak linking" and there was no such thing as Java or "C", just assembler and a simple linker !! not sure if you understand this? but in "the ole days" the linker could not handle these type of address jumps (JSR or JMP) - you understand ?? The compiler needed to know the address of the "routine" you wished to call (or in other words, the "method") at COMPILE time. You simply could not do a sort of ...

    class.activity.window().some_method()

    one would have to do the following:

    1. switch to/ensure protected mode.
    2. set segment register (SX) for class()
    3. set address register (AR) for class()
    4. call class and store 16 bit result on stack
    5. push stack
    6. do above using stack as parameter (pop)
    7.. and so on for activity
    8.. and so on for window
    9.... for some_method

    Phew!

    Isnt it so easy in java/android
     
  6. id0001

    id0001 Well-Known Member

    Joined:
    Apr 20, 2010
    Messages:
    142
    Likes Received:
    23
    Yeah I understand it.. partially. I haven't written any assembly. Also don't need to with all those managed languages. I'm glad I could answer your question.
     
  7. AlbertPucciani

    AlbertPucciani Well-Known Member

    Joined:
    Oct 2, 2010
    Messages:
    71
    Likes Received:
    8
    Easy in Android?! The Java language is 10X easier than assembly. I never dipped much into C/C++ until recently. If you know C, you should skip Android, get a Mac and program for the iPhone/iPod with Objective C.

    You need to know the address in C because C isn't object oriented. Java expects a Window Object back, that Window object could actually be abstract and extended (inherited) by a child class. If the Window object is not available when the Activity calls ".ctor' its only because they did a lazy init.

    public Window getWindow() {
    if (this.mWindow == null) {
    this.mWindow = new Window(this.context, etc, etc);
    this.mWindow.doStuff();
    this.mWindow.doMoreStuff(var1, var2);
    }
    return this.mWindow;
    }

    Hope my rant was useful.

    - Albert Pucciani
     

Share This Page

Loading...