The "listener" or "observer" pattern is the most common strategy for creating asynchronous callbacks in Android development.
Now on your Activity:
In the next step we need to define an instance variable in the object that will send callback via
MyCustomListener. And add setter for our listener.
Now, in other class, we can create instance of
next we can set our listener, to
sampleClass, in two ways:
MyCustomListener in our class:
or just instantiate an anonymous inner class:
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0