Understanding of Android Callbacks (combined interface)

Source: Internet
Author: User
Tags date now

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.