Some Questions about the failure of Android program to call Webservice on CSDN
Today, I found several examples of android webservice calls from books and CSDN. These examples show that there are no errors in the code, but they are not running successfully. After analyzing how android calls the web interface, we find that these examples do not run in a single thread during the call. Below we will post out the main code changes to the example "Android phone number query" downloaded from CSDN, hoping to help beginners who want to learn android.
FutureTask
FutureTask = new FutureTask
(New Callable
() {@ Overridepublic String call () throws Exception {try {// call WebServicetransport. call (soapAction, envelope); if (envelope. getResponse ()! = Null) {// get the returned data SoapObject object = (SoapObject) envelope. bodyIn; // obtain the returned result String result = object. getProperty (0 ). toString (); return result ;}} catch (Exception e) {e. printStackTrace () ;}return null ;}}); new Thread (futureTask ). start (); // display the results returned by WebService in TextView try {String result = futureTask. get (); resultView. setText (result);} catch (InterruptedException e) {// TODO Auto-generated catch blocke. printStackTrace ();} catch (ExecutionException e) {// TODO Auto-generated catch blocke. printStackTrace ();}