views:

31

answers:

1

Hi Friends,

I have been struggling with this problem for many days. please help me..

In my android application i am trying to download images from remote server dynamically ( no of images dynamically come ). for downloading all images it is taking 30 to 40 seconds mean time user has to wait to see the activity . But it is the worst case that loading activity after loading all images. I want to load activity first then load images one by one.

Is there anything to do it?

Thanks and Regards,

Kiran

+1  A: 

I think you need to implemet your code using "AsyncTask", for more info, refer this link: http://developer.android.com/reference/android/os/AsyncTask.html

for example:

public void onClick(View v) {
  new DownloadImageTask().execute("http://example.com/image.png");
}

private class DownloadImageTask extends AsyncTask {
     protected Bitmap doInBackground(String... urls) {
         return loadImageFromNetwork(urls[0]);
     }

     protected void onPostExecute(Bitmap result) {
         mImageView.setImageBitmap(result);
     }
 }

See in above example, Write your code for downloading images inside "doInBackground()" function and write the code for displaying iamges inside "onPostExecute()" function.

Enjoy!!

PM - Paresh Mayani
Thank you very much Paresh Mayani.
Chanda Kiran
@Chanda Kiran glad about your reply
PM - Paresh Mayani