I wrote a wallpaper app for Android. I used Picasso for download, cache and show images from given URLs.
In mainActivity I have a Gridview which images load inside it.
And in ActivityTwo I have Imageview which shows the selected image but the problem is that image load very very slowly (for example a 300Kb image load in 10 secs).
How can I make images load faster?
Here is my codes:
MainActivity.Java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this, ActivityTwo.class);
intent.putExtra("position", position);
startActivity(intent);
}
});
}
// our custom adapter
private class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context context) {
mContext = context;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView imageView;
// check to see if we have a view
if (convertView == null) {
// no view - so create a new one
imageView = new ImageView(mContext);
} else {
// use the recycled view object
imageView = (ImageView) convertView;
}
// Picasso.with(MainActivity.this).setDebugging(true);
Picasso.with(MainActivity.this)
.load(mThumbIds[position])
.placeholder(R.raw.place_holder)
.error(R.raw.big_problem)
.noFade().resize(250, 250)
.into(imageView);
return imageView;
}
}
static String[] mThumbIds = {
//My Links Here
};
}
Try Glide library. It loads images faster than Picasso library. For more details refer this link. Libraries to include
dependencies {
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:support-v4:22.0.0'
}
Use this to load images :
Glide.with(context)
.load("http://inthecheesefactory.com/uploads/source/glidepicasso/cover.jpg")
.into(ivImg);