0

I am a novice but I have already read What is callback in Android and How to define callbacks in Android.

I think that I got the point in this kind of examples:
button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick (View v){ // my code } });

In many books I have found that methods used for managing the life cycle of the Activity (such as protected void onCreate(Bundle savedInstanceState)) are defined as Callback Methods.

Why onCreate() is a Callback Method? Which is the function passed as an argument?
I have a Bundle as an argument, I don't see any Interface or function used as an argument.

Community
  • 1
  • 1
titiro89
  • 2,058
  • 1
  • 19
  • 31
  • "Why onCreate() is a Callback Method?" -- because our activity is being called into from an outside party, in this case some framework code. "I think that I got the point in this kind of examples" -- that is simply one way of registering a callback, for a narrow role (respond to a click event). – CommonsWare Nov 27 '16 at 17:25
  • @CommonsWare thank you, the second part is very clear. I will edit the question in order to talk about the first part of your answer. – titiro89 Nov 27 '16 at 18:53
  • @CommonsWare finally I have understood what you told in the first part. In my mind I had only a strict definition of "callback" and with that belief I couldn't get the point. Comments at this link [What is a callback function](http://stackoverflow.com/questions/824234/what-is-a-callback-function) helped me a lot. – titiro89 Nov 30 '16 at 09:52
  • @CommonsWare are there any more details you can provide about `our activity is being called into from an outside party`? Also is there a resource you recommend to garnering a deeper understanding of android? It's still not really clear to me how onCreate() is a callback. – Lv99Zubat Apr 22 '17 at 18:29
  • "It's still not really clear to me how onCreate() is a callback" -- you are not calling `onCreate()` yourself. Hence, it is a callback. I don't really know how else to explain it. "Also is there a resource you recommend to garnering a deeper understanding of android?" -- if you mean a deeper understanding of how to write Android apps, there are [books](https://commonsware.com/Android). If you mean a deeper understanding of how Android itself works, there are [books](http://shop.oreilly.com/product/0636920021094.do). – CommonsWare Apr 22 '17 at 18:37

0 Answers0