Bear in mind that the code shown below runs on the UI thread. This means the UI thread is blocked until the HTTP request returns. If the HTTP request has a problem (e.g., the server is not responding), it could very easily take beyond the ~5 seconds allowed before an application-not-responding (ANR) error occurs and your activity is forcibly closed.
I heartily encourage you to use a placeholder image when launching your UI and have the real image downloaded off the Web in the background. AsyncTask should work very well for this case -- you can download and decode the image in doInBackground() and apply it to the ImageView in onPostExecute(). Nithin Varamballi wrote: > hi... > > I did like this.. This may help you.... > > public class demo extends Activity { > /** Called when the activity is first created. */ > > ImageView i1; > public int position=0; > private String[] myRemoteImages = { > "http://www.cssnz.org/flower.jpg"}; > > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > button1 = (Button) findViewById(R.id.clear); > i1 =(ImageView) findViewById(R.id.i1); > load(); > > > } > } > public void load() > { > > try > { > URL aURL = new URL(myRemoteImages[i]); > URLConnection con = aURL.openConnection(); > con.connect(); > InputStream is = con.getInputStream(); > /* Buffered is always good for a performance plus. */ > BufferedInputStream bis = new BufferedInputStream(is); > /* Decode url-data to a bitmap. */ > Bitmap bm = BitmapFactory.decodeStream(bis); > i1.setImageBitmap(bm)); > bis.close(); > is.close(); > /* Apply the Bitmap to the ImageView that will be returned. > */ > > } > catch (IOException e) > { > Log.e("DEBUGTAG", "Remtoe Image Exception", e); > } > > } > > Thank You > Nithin N V > > > -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android App Developer Training: http://commonsware.com/training.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---