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