i'm trying to create an application contains different categories and each category contains range of images (All images are downloaded from their links) and i working with Glide Library ,i did all that but have problem with memory ram my application take a lot of memory (The value varies depending on the device) reason of that is when i moving between categories The images are loaded and stored in the cache , how i can fix this issue
this one of fragments .java
public class Art extends Fragment {
GridView myGrid;
CategoryAdapter adapter;
public Art() {
// Required empty public constructor
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
final ArrayList<String> movieList = new ArrayList<>();
/*Source Art*/
movieList.add("http://i.imgur.com/INlyb2w.jpg");
movieList.add("http://i.imgur.com/ZvvBaq8.jpg");
/*****/
View v = inflater.inflate(R.layout.fragment_art, container, false);
myGrid= (GridView) v.findViewById(R.id.gridViewCategory);
adapter =new CategoryAdapter(getActivity(),movieList);
myGrid.setAdapter(adapter);
myGrid.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent popup = new Intent(getActivity(), Pop.class);
popup.putExtra("WallpaperURL", movieList.get(position));
startActivity(popup);
}
});
return v;
}
}
class CategoryAdapter extends BaseAdapter {
private Context context;
private ArrayList<String> imageId= new ArrayList<>();
CategoryAdapter(Context context,ArrayList<String> imageId){
this.context=context;
this.imageId=imageId;
}
@Override
public int getCount() {
return imageId.size();
}
@Override
public Object getItem(int position) {
return imageId.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder{
ImageView CategoryImage;
ViewHolder(View view){
CategoryImage = (ImageView) view.findViewById(R.id.cat_imageView);
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
ViewHolder holder;
if(row == null){
LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.picture_item,parent,false);
holder=new ViewHolder(row);
row.setTag(holder);
}
else{
holder=(ViewHolder) row.getTag();
}
Glide.with(context).load(imageId.get(position)).placeholder(R.drawable.arrw).into(holder.CategoryImage);
return row;
}
}