Android的内存不足

时间:2017-03-17 09:56:49

标签: php android sql-server json

我有一个问题,使用类型byte []将图像从数据库恢复到android,我们将ArrayList图像传递给我们使用Glide的适配器,但我可以使用服务网络恢复20多个数据库图像PHP,应用程序返回异常“内存不足!!”

我希望你能帮助我找到解决这个问题的方法我尝试的不仅仅是解决方案,但我还是有问题

public class CardAdapter extends RecyclerView.Adapter<CardAdapter.MyTag>
{
LayoutInflater inflater;
DbConnection db ;
CnxExternal myConex = new CnxExternal();
ArrayList<Map<String, String>> listitem;
private CardAdapter.MyTag holder;
Context ctx;
ArrayList<byte[]> img , imgfou ;
ArrayList<String>nomesFo,descriptions;
String codeBar;
ArrayList<Integer>idfourns;



public CardAdapter(Context context, ArrayList<Map<String, String>> list,ArrayList<byte[]>imagbyt,ArrayList<String>names,ArrayList<Integer>idf,String cod,ArrayList<String>Description,ArrayList<byte[]>imagfour) {
    super();
    this.inflater = LayoutInflater.from(context);
    this.listitem = list;
    ctx=context;
    this.img=imagbyt;
    this.nomesFo=names;
    this.idfourns=idf;
    this.codeBar=cod;
    this.imgfou=imagfour;
    this.descriptions=Description;
    db =new DbConnection(ctx);

}

public class MyTag extends RecyclerView.ViewHolder {
    TextView price;
    TextView name;
    ImageView img;
    TextView namfou;
    TextView rating;
    FloatingActionButton btnlike;

    CardView cardView;
    public MyTag(View view) {
        super(view);
        //for animat
cardView=(CardView)view.findViewById(R.id.card_view);

        price = (TextView) view.findViewById(R.id.prixprodtestcard);
        name = (TextView) view.findViewById(R.id.nomprodtestcard);
        namfou=(TextView) view.findViewById(R.id.qtestockcard);
        rating=(TextView)view.findViewById(R.id.rating);
        img = (ImageView) view.findViewById(R.id.imageprodcard);
        btnlike = (FloatingActionButton) view.findViewById(R.id.likeButtoncard);
}
}


@Override
public MyTag onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, null);

    return new MyTag(v);
}


@Override
public int getItemCount() {
    return listitem.size();
}


@Override
public void onViewRecycled(MyTag holder) {
    super.onViewRecycled(holder);
    Glide.clear(holder.img);
}

public void onBindViewHolder(final MyTag holder, final int position) {

    //anim fadein
    YoYo.with(Techniques.SlideInUp)
            .playOn(holder.cardView);

    final HashMap<String, String> map = (HashMap<String, String>)listitem.get(position);


    if(map.get("like").equals("0")){
        holder.btnlike.setImageResource(R.drawable.heart);
    }else{
        holder.btnlike.setImageResource(R.drawable.ic_liked);

    }
    holder.img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(ctx,InformationsProduit.class);
            i.putExtra("nomProd",map.get("name"));
            i.putExtra("prix",map.get("price"));
            i.putExtra("nomFour",nomesFo.get(position));
            i.putExtra("image",img.get(position));
            i.putExtra("telFour",map.get("telefournisseur"));
            i.putExtra("addrFour",map.get("adressFou"));
            i.putExtra("idFour",idfourns.get(position));
           i.putExtra("description",descriptions.get(position));
            i.putExtra("codeBar",codeBar);
            ctx.startActivity(i);
        }
    });

    holder.price.setText(map.get("price"));
    holder.name.setText(map.get("name"));
    holder.namfou.setText(nomesFo.get(position));
    holder.rating.setText(map.get("rating"));


    Glide.with(ctx)
            .load(imgfou.get(position))
            //.diskCacheStrategy( DiskCacheStrategy.NONE )
            //.skipMemoryCache( true )
            .thumbnail(0.1f)
            .into(holder.img);


    holder.btnlike.setOnClickListener(new View.OnClickListener() {
        CardAdapter.MyTag hld=holder;
        int pos=position;
        @Override
        public void onClick(View arg0) {

            HashMap<String, String> mapclicked = (HashMap<String, String>)listitem.get(pos);
            if(mapclicked.get("like").equals("0"))
            {
                hld.btnlike.setImageResource(R.drawable.ic_liked);
                mapclicked.put("like", "1");


                Snackbar snackbar;
                snackbar = Snackbar.make(hld.btnlike, "Bien ajouter au prefere", Snackbar.LENGTH_SHORT);
                View snackBarView = snackbar.getView();
                snackBarView.setBackgroundColor(Color.GREEN);
                TextView textView = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_text);
                textView.setTextColor(Color.WHITE);
                snackbar.show();

                db.insertFav(codeBar,idfourns.get(pos) , map.get("name") , map.get("price") , nomesFo.get(position) , map.get("adressFou") , map.get("telefournisseur") ,img.get(position) );

                hld.btnlike.startAnimation(animAdp());

            }else{
                hld.btnlike.setImageResource(R.drawable.heart);
                mapclicked.put("like", "0");

        Snackbar.make(hld.btnlike, "Removed from prefere" , Snackbar.LENGTH_LONG).setAction("Action", null).show();

                db.deleteR(codeBar,idfourns.get(pos));
                hld.btnlike.startAnimation(animAdp());
            }
        }}
    );



}

1 个答案:

答案 0 :(得分:0)

在标记AndroidManifest.xml内的<Application>中添加此内容:

android:hardwareAccelerated="false"
android:largeHeap="true"