java - drawable from an url with honeycomb -


from beginning used method :

 public drawable createportrait(string url){     try {         inputstream = (inputstream)new url(url).getcontent();         drawable d = drawable.createfromstream(is, "image");         return d;     } catch (malformedurlexception e) {         // todo auto-generated catch block         e.printstacktrace();         return null;     } catch (ioexception e) {         // todo auto-generated catch block         e.printstacktrace();         return null;     }  } 

but honeycomb doesn't allow me anymore, see in log : android.os.networkonmainthreadexception . thing url taken json data :

 private class graburl extends asynctask<string, void, void> {     private final httpclient client = new defaulthttpclient();     private string content;     private string error = null;     private progressdialog dialog = new progressdialog(main.this);      protected void onpreexecute() {         dialog.setmessage("downloading source..");         dialog.show();     }      protected void doinbackground(string... urls) {         try {             httpget httpget = new httpget(urls[0]);             responsehandler<string> responsehandler = new basicresponsehandler();             content = client.execute(httpget, responsehandler);         } catch (clientprotocolexception e) {             error = e.getmessage();             cancel(true);         } catch (ioexception e) {             error = e.getmessage();             cancel(true);         }          return null;     }     protected void onpostexecute(void unused) {         dialog.dismiss();         if (error != null) {             toast.maketext(main.this, error, toast.length_long).show();         } else {             toast.maketext(main.this, "source: " + content, toast.length_long).show();         }         object o = new gson().fromjson(content, info.class);         info = (info)o;         string d = i.getdata().get(0).getlg_portrait();         portrait.setbackgrounddrawable(createportrait(d));     } 

}

and portrait imageview . don't know .

you need download image in async task well. honeycomb not let run lengthy http operation blocking ui thread (reading stream makes http call , waits image downloaded). should return placeholder immediately, trigger asynctask , replace image after downloaded.

hint "post execute" run in ui thread....


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -