Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By JosAH

Thread: Callback Methods

  1. #1
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default Callback Methods

    I have never understood the concept of callback functions properly. Now I am studying java and android programming. and I have encountered this method.

    Java Code:
    public void onCreate(Bundle savedInstanceState){
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_main);
    }
    From my understanding of normal methods, inside the implementation of this method, this method is calling itself, so the implementation will start again and it will call itself again, and so on... which results in an infinite loop of calling and starting implementation of this method.

    Can somebody suggest me some document/tutorial etc. which is short and easy, and which explains what callback methods are and what is the flow of their execution.

    OR

    Can somebody tell me in a simple way the flow of execution of the implementation of this method onCreate() and why is the call to the method itself needed and what this call actually does.

    Please reply ASAP, I'll be grateful, since I have my work dependent on this concept.
    Don't forget to smile :-)

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,001
    Blog Entries
    7
    Rep Power
    20

    Default Re: Callback Methods

    The class where that method is defined has a super class; that super class also has a definition for that method; it is that super class definition that is called in line #2.

    kind regards,

    Jos
    Nazneen Ali likes this.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default Re: Callback Methods

    The class where that method is defined has a super class; that super class also has a definition for that method; it is that super class definition that is called in line #2.

    kind regards,

    Jos



    Thank you very much!
    Don't forget to smile :-)

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default Re: Callback Methods

    <nitpick>
    That isn't an example of a callback method. A method in class Foo calls a method in class Bar which calls a method in class Foo. That is a callback.
    </nitpick>

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: Callback Methods

    To add to what Junky said... a common callback pattern is where you have a method that takes an object as an argument, and the method (or something the method starts) calls some method on the object you gave it. The android-async-http library is a good example. You pass a ResultHandler (which is an interface) to a method that performs, say, a HTTP GET. The method you called returns quickly, but some time later, some worker thread queues up a task in the UI thread that calls onSuccess(...) or onFailure(...) on your ResultHandler. That's a callback.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Non blocking callback method
    By Bibhukalyana in forum New To Java
    Replies: 4
    Last Post: 04-11-2013, 06:53 PM
  2. use api without callback url?
    By Seiya0890 in forum New To Java
    Replies: 0
    Last Post: 03-02-2013, 05:02 PM
  3. query with a callback?
    By Filobel in forum JDBC
    Replies: 4
    Last Post: 01-20-2012, 09:33 AM
  4. JNA-How to define a masage to recive callback?
    By lipkerson in forum Advanced Java
    Replies: 0
    Last Post: 05-28-2010, 12:10 PM
  5. Setting a timeinterval callback ???
    By wallys in forum New To Java
    Replies: 1
    Last Post: 08-19-2008, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •