Android implementation of asynchronous problems small experience Summary

Source: Internet
Author: User

1. As stated, the subclass of the asynchronous task must be called in the UI thread

2, after the wall test

1--, method one @Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Thread Thread=NewThread (NewRunnable () {@Override Public voidrun () {uploaddd ();               }            }); Thread.Start ();2--, method twoPrivate voiduploaddd () {final Handler Handler=NewHandler () { Public voidhandlemessage (Message msg) {if(msg.what==1) {LOG.D ("DFDFDFDF", ii+"__"+"Haode");        }            }        }; Thread Thread=NewThread (NewRunnable () {@Override Public voidrun () {LOG.D ("DFDFDFDF", ii+"__"); Handler.sendemptymessage (1);        }        });    Thread.Start (); }

The above code hangs out to prove that a method called in a non-UI continues to open the thread while there is an exception to the handler mechanism (because handler is an asynchronous mechanism)

The experiment concludes that the following code does not appear to be abnormal

The@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Thread Thread=NewThread (NewRunnable () {@Override Public voidrun () {uploaddd ();               }            }); Thread.Start ();2--Private voiduploaddd () {//final Handler handler=new Handler ()//        {//Public void Handlemessage (Message msg)//            {//if (msg.what==1)//                {//log.d ("Dfdfdfdf", ii+ "__" + "Haode");////if (Androidclient._error_uploadscrapimgfile.intern ()! = "")////                    {////Toast.maketext (Activityscrap.this,androidclient._error_uploadscrapimgfile,toast.length_short). Show ();////                    }//                }//            }//        };Thread thread =NewThread (NewRunnable () {@Override Public voidrun () {LOG.D ("Dfdfdfdf", ii+ "__"); Androidclient.uploadscrapimgfile (Scrapimgdatas,ii+"__"); //handler.sendemptymessage (1);            }        });    Thread.Start (); }

Android implementation of asynchronous problems small experience Summary

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.