android - What is the use of hit api in async task? -


can use httpget/httppost without async??

 httpclient client = new defaulthttpclient();     httpget request = new httpget("http://www.example.com");  

if using without async, gives threat error.

this exception occurs due heavy task performed on main thread. if performing task takes time may comes error.to handle have use thread run type of code. there no need of run code inside asynctask network operation should inside thread this.but asynctask better option type of operations suggest that.

thread thread = new thread(new runnable(){     @override     public void run() {         try {             //your code goes here         } catch (exception e) {             e.printstacktrace();         }     } });  thread.start(); 

also can change default behavior using following

strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build();  strictmode.setthreadpolicy(policy);  

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -