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.
1
-
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– Hemant Parmar2018-01-16 05:37:22 +00:00Commented Jan 16, 2018 at 5:37
Add a comment
|
1 Answer
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
}
});