android - update Main UI Thread or AsyncTask never allowed than where can i update UI thread? -
this question has answer here:
caused by: android.os.networkonmainthreadexception 04-25 13:15:52.362: e/androidruntime(20900): @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1117) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.io.blockguardos.connect(blockguardos.java:84) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.io.iobridge.connecterrno(iobridge.java:127) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.io.iobridge.connect(iobridge.java:112) 04-25 13:15:52.362: e/androidruntime(20900): @ java.net.plainsocketimpl.connect(plainsocketimpl.java:192) 04-25 13:15:52.362: e/androidruntime(20900): @ java.net.plainsocketimpl.connect(plainsocketimpl.java:459) 04-25 13:15:52.362: e/androidruntime(20900): @ java.net.socket.connect(socket.java:842) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpconnection.<init>(httpconnection.java:76) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpconnection.<init>(httpconnection.java:50) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpconnection$address.connect(httpconnection.java:340) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:87) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpconnection.connect(httpconnection.java:128) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:316) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpengine.connect(httpengine.java:311) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:290) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpengine.sendrequest(httpengine.java:240) 04-25 13:15:52.362: e/androidruntime(20900): @ libcore.net.http.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:81) 04-25 13:15:52.362: e/androidruntime(20900): @ java.net.urlconnection.getcontent(urlconnection.java:190) 04-25 13:15:52.362: e/androidruntime(20900): @ java.net.url.getcontent(url.java:447) 04-25 13:15:52.362: e/androidruntime(20900): @ biz.xicom.printvintage.homescreen$2.run(homescreen.java:199) 04-25 13:15:52.362: e/androidruntime(20900): @ android.app.activity.runonuithread(activity.java:4644) 04-25 13:15:52.362: e/androidruntime(20900): @ biz.xicom.printvintage.homescreen.setview(homescreen.java:193) 04-25 13:15:52.362: e/androidruntime(20900): @ biz.xicom.printvintage.homescreen.oncreate(homescreen.java:58) 04-25 13:15:52.362: e/androidruntime(20900): @ android.app.activity.performcreate(activity.java:5104) 04-25 13:15:52.362: e/androidruntime(20900): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 04-25 13:15:52.362: e/androidruntime(20900): @ android.app.activitythread.performlaunchactivity(activitythread.java:2144)
code
(int = 0; < image_list.size(); i++) { layoutinflater layoutinflator = homescreen.this.getlayoutinflater(); linearlayout childlayout = (linearlayout) layoutinflator.inflate( r.layout.image_text_web_services_inflate, mpager, false); im = (imageview) childlayout.findviewbyid(r.id.image_web_service); t = (textview) childlayout.findviewbyid(r.id.text_web_service); t.settext(homescreen.detail_list.get(i)); final int j=i; runonuithread(new runnable() { public void run(){ try { bitmap bitmap = bitmapfactory .decodestream((inputstream) new url( homescreen.image_list.get(j)) .getcontent()); im.setimagebitmap(bitmap); } catch (malformedurlexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } }); mpager.addview(childlayout); }
i read below link:
load more - original thread created view hierarchy can touch views
android - caused by: android.view.viewrootimpl$calledfromwrongthreadexception
every 1 said
you trying update main ui thread or asynctask never allowed that.
then can update or show image.
also try asynctask. than how implement on loop
use code help,
strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy);