0

Errors Coming on app crash

08-27 23:32:33.714 1178-1223/com.statusstock.wallpaperhd I/art: Clamp target GC heap from 398MB to 384MB
08-27 23:32:33.715 1178-1223/com.statusstock.wallpaperhd I/art: Alloc concurrent mark sweep GC freed 9(288B) AllocSpace objects, 0(0B) LOS objects, 0% free, 382MB/384MB, paused 533us total 58.639ms
    Forcing collection of SoftReferences for 3MB allocation
    Starting a blocking GC Alloc
08-27 23:32:33.766 1178-1223/com.statusstock.wallpaperhd I/art: Clamp target GC heap from 398MB to 384MB
    Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 382MB/384MB, paused 439us total 51.432ms
08-27 23:32:33.766 1178-1223/com.statusstock.wallpaperhd W/art: Throwing OutOfMemoryError "Failed to allocate a 3686412 byte allocation with 1976816 free bytes and 1930KB until OOM"
08-27 23:32:33.766 1178-1223/com.statusstock.wallpaperhd D/skia: --- decoder->decode returned false

This is a Wallpaper App and it shows images in grid view with the help of Picasso by retrieving the image URL from the firebase. If you click on an image it opens in a new activity with the help of Picasso and firebase. But when I am running my app it is taking too much memory and app crashes after using for some minutes. I have used android:hardwareAccelerated="false" and android:largeHeap="true" but these are not working.

Code:

Viewholder.java

import ...

public class ViewHolder extends RecyclerView.ViewHolder {

    View mView;

    public ViewHolder(final View itemView) {
        super(itemView);

        mView = itemView;

        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mClickListener.onItemClick(v, getAdapterPosition());
            }
        });

        itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {

                mClickListener.onItemLongClick(v, getAdapterPosition());
                return true;
            }
        });

    }


    public void setDetails(Context ctx, String image){


        ImageView mImageTv = mView.findViewById(R.id.rImageView);

        Picasso.get().load(image).into(mImageTv);

    }


    private ViewHolder.ClickListener mClickListener;

    public interface ClickListener{

        void onItemClick(View view, int position);
        void onItemLongClick(View view, int position);

    }

    public void setOnclickListener(ViewHolder.ClickListener clickListener){

        mClickListener = clickListener;

    }


}

Fragments Showing wallpapers in Grid View

public class HDFragment extends Fragment {

    RecyclerView mRecyclerView;
    FirebaseDatabase mFirebaseDatabase;
    DatabaseReference mRef;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_hd, container, false);


        mRecyclerView = view.findViewById(R.id.recyclerView_hd);
        mRecyclerView.setHasFixedSize(true);


        mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3));


        mFirebaseDatabase = FirebaseDatabase.getInstance();
        mRef = mFirebaseDatabase.getReference("New");

        FirebaseRecyclerAdapter<Model, ViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Model, ViewHolder>(Model.class, R.layout.row, ViewHolder.class, mRef) {
            @Override
            protected void populateViewHolder(ViewHolder viewHolder, Model model, int position) {

                viewHolder.setDetails(getActivity().getApplicationContext(), model.getImage());

            }

            @Override
            public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


                ViewHolder viewHolder = super.onCreateViewHolder(parent, viewType);
                viewHolder.setOnclickListener(new ViewHolder.ClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {

                        String mImage = getItem(position).getImage();


                        Intent intent = new Intent(view.getContext(), PostDetailsActivity2.class);

                        intent.putExtra("image", mImage);
                        startActivity(intent);


                    }

                    @Override
                    public void onItemLongClick(View view, int position) {


                    }
                });


                return viewHolder;
            }
        };


        mRecyclerView.setAdapter(firebaseRecyclerAdapter);


        return view;
    }
}

FullImage Activity shows the image in full screen when it clicked

mImageTv = findViewById(R.id.full_imageView1);

        String image = getIntent().getStringExtra("image");


        Picasso.get().load(image).fit().centerCrop().memoryPolicy(MemoryPolicy.NO_CACHE).into(mImageTv);

Please help..Thank you

2 Answers2

0

If you really need more memory you can set in the Manifest this attribute for Application that could solve the problem (maybe):

android:largeHeap="true"

though it does not come for free as you can read in this post: What are advantages of setting largeHeap to true?

0

You are trying to load a big image, reduce the resolution of the image or use a view that handles large images, such as this.

Levon Petrosyan
  • 8,815
  • 8
  • 54
  • 65