Here is a classic example of how the callback is implemented, in which the mechanism contains
Two classes and an interface, the interface is defined as follows:
// equivalent to the interface ina Public Interface boomwtc{ // Get Bin Laden's decision public benladengdecide () ; // execution of the bombing of WTO Public void boom ();}
Class A is defined as follows, as a main class that implements the interface
//equivalent to class A Public classat$911Implementsboomwtc{Private Booleandecide; PrivateTerroristattack Ta;//Class B PublicAt$911 () {//constructor FunctionDate now=NewDate (); SimpleDateFormat MYFMT1=NewSimpleDateFormat ("Yy/mm/dd hh:mm"); This. dicede= myfmt.format (dt). Equals ("01/09/11 09:44"); This. ta=NewTerroristattack (); } //the decision to get Bin Laden Public Booleanbenladengdecide () {returndecide; } //execution of the bombing of WTO Public voidBoom () {Ta.attack (Newat$911);//Class A calls the Class B method to pass in its own object, which is equivalent to "You Call Me" }}
Class B is defined as follows:
Public class terroristattack{ public terroristattack () { } public attack ( BOOMWTC BMW) { // Call the method in Class A if(Bmw.benladengdecide ()) {/ * Class B's method of callback Class A in the method, equivalent to "I call you back"*/ }} }
As can be seen from the example, Class B is a way to callback Class A through an interface
Understanding of Android Callbacks (combined interface)