Android open thread, asynchronous processing data instance

Source: Internet
Author: User

Package com.example.sywang2;

Import COM.ZDS.OS.R;

Import Android.os.Bundle; Import Android.os.Handler; Import android.app.Activity; Import Android.view.Menu; Import Android.view.View; Import Android.widget.Button; Import Android.widget.TextView;

public class Mainactivity extends Activity {private TextView text;  Private Button btn1;   @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);   Setcontentview (R.layout.activity_main);   text= (TextView) Findviewbyid (r.id.txt);  btn1= (Button) Findviewbyid (R.ID.BTN); }

  @Override  public boolean oncreateoptionsmenu (Menu menu) {  //inflate the menu; this adds items to The Action Bar if it is present.   getmenuinflater (). Inflate (R.menu.main, menu);   return true;  }    //defines a Handler that is used to process data asynchronously     Handler Handler = new Handler () {         public void Handlemessage (Android.os.Message msg) {             System.out.println ("results returned, processing ....");                          if (msg.what = = 1) {                 Text.settext ("Asynchronous processing results are = = = = = Handler");                 Thread.stop ();            }                    };    };            //new thread for asynchronous processing of data, results returned by handler     thread thread = new Thread () {        public void run () {     & nbsp;      System.out.println ("Start thread,,,,");                          handler.sendemptymessage (1);        };    };            //click button     public void Starttest (View v) {         Thread.Start ();                 try {             THread.sleep (2000);         catch (Interruptedexception e) {            //TODO auto-generated catch block              E.printstacktrace ();        }                  System.out.println ("OnClick,,,,");    }    

}

Android open thread, asynchronous processing data instance

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.