i am downloading (pref-etch) images from server at some time of interval
so i wanted to know what is the best way to download images
asyntask
service
intentservice
please help
i am downloading (pref-etch) images from server at some time of interval
so i wanted to know what is the best way to download images
asyntask
service
intentservice
please help
Case 1: If you have to download very few images (like one or two in an activity) from Internet, then use Asynctask .
Case 2: If you have to download many images specially for ListView items , you must have to implement it in a dedicated background thread by using HandlerThread, Handler , message and Looper in Android. Avoid using a service here. Also, you have to implement image caching as you dont want to download the same image multiple times in a session.
Advice: If the second is your case, don't implement the above by yourself. Save your time and use some awesome, efficient and fast libraries used by millions of Android apps.
You can use:
Edit: How to use Picasso for downloading images.
All the above mentioned libraries can do that beautifully. I am sharing the solution with Picasso.
Picasso.with(mContext).load("url").into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
//save the bitmap into permanent storage or do whatever you want like showing in some ImageView etc.
}
@Override
public void onBitmapFailed(Drawable drawable) {
}
@Override
public void onPrepareLoad(Drawable drawable) {
}
});
Hope this helps. If still have any issue , please feel free to comment.