1

I want to understand the concept of callback. I have searched on internet about the callbacks and there are many examples using interface, and one class is calling a method of another class using that interface. But still I can't get the main concept of callbacks, what is the purpose of using callbacks? Give real time example using callbacks.

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
sheik
  • 11
  • 3
  • Real time example is : I open the camera and capture the image, now i want this image to my app image view, how you get? process is: 1. call intent for open camera !.e Request 2. get camera image in onActivityResult() method that is call back, now we can whatever we want on this method. hope you understood my point. – Hemant Parmar Jan 16 '18 at 05:37

1 Answers1

0

Callback is generally used to get a trigger or a call to our method for execute some code snippet after a particular action.

For example, When we use Button in android, we need the callback of click. so we set onClick listner and we write our code snippet in it.

Button button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new OnClickListener()
    {
      public void onClick(View v)
      {
         // Callback gets triggered when button clicks
      }
    });
Jithu S
  • 76
  • 3