java - Showing progress image between httpGet and response in Android -


i use code below xml file web service :

public string getxmlfromurl(string url) {          string xml = null;          try {             // defaulthttpclient             defaulthttpclient httpclient = new defaulthttpclient();             httpget httpget = new httpget(url);              httpresponse httpresponse = httpclient.execute(httpget);             httpentity httpentity = httpresponse.getentity();             xml = entityutils.tostring(httpentity,"utf-8");          } catch (unsupportedencodingexception e) {             e.printstacktrace();         } catch (clientprotocolexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }         // return xml         return xml;     } 

it takes 3-4 seconds web service response request. want display image in time between request , response.

what best way so?

any appreciated.

use asynctask

private class longoperation extends asynctask<string, void, string> {          @override         protected void onpreexecute() {           // show image here         }         @override         protected string doinbackground(string... params) {              string xml = null;          try {             // defaulthttpclient             defaulthttpclient httpclient = new defaulthttpclient();             httpget httpget = new httpget(url);              httpresponse httpresponse = httpclient.execute(httpget);             httpentity httpentity = httpresponse.getentity();             xml = entityutils.tostring(httpentity,"utf-8");          } catch (unsupportedencodingexception e) {             e.printstacktrace();         } catch (clientprotocolexception e) {             e.printstacktrace();         } catch (ioexception e) {             e.printstacktrace();         }             return null;         }              @override         protected void onpostexecute(string result) {         /handle result server         }           @override         protected void onprogressupdate(void... values) {         } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -