Android: put URL code in AsyncTask -


How can I insert the following text in AsyncTask ? My problem is that by getting the code I get an error NetworkOnMainThreadException I need any help Please try it

  try {url myFileUrl = new URL ("http : //.../cercanias.png "); HttpURL connection conn = (HttpURLConnection) myFileUrl.openConnection (); Conn.setDoInput (true); Conn.connect (); InputStream = conn.getInputStream (); Bitmap BM = BitMapfichture Decodestream (is); FileOutputStream Out = New FileOutputStream (getCacheDir () + "cercanias.png"); bm.compress (bitmap.compress format.png, 90, out); See Submompling Scale Image View Image = (Submommeling Scale Image View) Find VVBIID (RID imgannitida); imageView.setImageFile (getCacheDir () + "cercanias.png"); Out.close (); If (Saved InstantState! = Empty & amp; Saved Instantstate Caninees (STATE_SCALE) & amp; amp; amp; amp; amp; amp; amp; amp; AgentState.Centenske (STATE_CENTER_X) & amp; ; amp; amp; amp; & amp; amp; & amp; amp; amp; & amp; amp; amp; & amp; amp; amp; saved & quot ;.contentkilli (STATE_CENTER_Y)} {imageView.SsetScaleAndCenter (SavedInstanceState.getFloat (STATE_SCALE), new point (savedinstenstate.getflat (STATE_CENTER_X), savedinstancestight.getflat (STATE_CENTER_Y)); }} Hold (IOException e) {}    

class testAsyncTask asyncTask and lt ; String, integer, integer & gt; {Protected integer doInBackground (string ... wires) {// long-running tasks - each passing string URL processing says myFileUrl = new URL ("http: //.../cercanias.png"); HttpURL connection conn = (HttpURLConnection) myFileUrl.openConnection (); Conn.setDoInput (true); Conn.connect (); InputStream = conn.getInputStream (); Bitmap BM = BitMapfichture Decodestream (is); FileOutputStream Out = New FileOutputStream (getCacheDir () + "cercanias.png"); bm.compress (bitmap.compress format.png, 90, out); Out.close (); Return 0; } PostExecute (integer result) {Log.d ("TestP", "AsyncTask returned:" + result) at protected zeros; See Submompling Scale Image View Image = (Submommeling Scale Image View) Find VVBIID (RID imgannitida); imageView.setImageFile (getCacheDir () + "cercanias.png"); If (Saved InstantState! = Blank and saved InstantState catcases (STATE_SCALE) & amp; amp; amp; amp; amp; amp; amp; amp; AgencyState.Centenske (STATE_CENTER_X) & amp; amp; Amp; amp; amp; amp; amp; agent; State.containsKey (STATE_CENTER_Y) {imageView.SsetScaleAndCenter (SavedInstanceState.getFloat (STATE_SCALE), new point (savedinstenstate.getflat (STATE_CENTER_X), savedinstenstight Gateflat (STATE_CENTER_Y)); }}

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -