0

i have a fragment which displays a gridview with images.

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

    gridView = (GridView) v.findViewById(R.id.gridView);
    gridAdapter = new GridViewAdapter(getActivity(), R.layout.grid_item_layout, getData(getActivity()));
    gridView.setAdapter(gridAdapter);

    gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageItem item = (ImageItem) parent.getItemAtPosition(position);
            //Create intent
            Intent intent = new Intent(getActivity(), FullScreenImageActivity.class);
            intent.putExtra("title", item.getTitle());
            ByteArrayOutputStream bs = new ByteArrayOutputStream();
            item.getImage().compress(Bitmap.CompressFormat.PNG, 50, bs);
            intent.putExtra("image", bs.toByteArray());
            //Start details activity
            startActivity(intent);
        }
    });

    return v;
}

When an item is clicked, i'm displaying a FullScreen Activity with the image that the user is clicking. The above code works perfectly when i click all the images except of the first. When the first item of the gridview is clicked the app is closing, without having any errors.

Any idea about that?

Ziem
  • 6,579
  • 8
  • 53
  • 86
chris.b
  • 33
  • 6
  • post your full error – N J Apr 25 '15 at 16:35
  • as i said i get no error in logcat :( if i had got any indication of error i would be able to debug it. – chris.b Apr 25 '15 at 16:45
  • Don't pass image data in intent. Instead store image in cache directory and pass path of image in intent. – Dhaval Patel Apr 25 '15 at 16:46
  • @DhavalPatel thanks for that, as i mention on my question the above code works fine, for all images in my gridview except from the first. That is why i am asking for any ideas. I don't wont to pass them via cache cause it will save me some searching and loading. – chris.b Apr 25 '15 at 16:48
  • 1
    Can you please check the size of first image. Because there is a limit on data that you can pass via intent. – Dhaval Patel Apr 25 '15 at 16:50
  • Take a look on [this](http://stackoverflow.com/questions/4878159/android-whats-the-best-way-to-share-data-between-activities#4878259). May be it will help you to solve your problem. – Dhaval Patel Apr 25 '15 at 16:55
  • @DhavalPatel in general i have tried several things from that link, but i still don't know what is the exact culprit, but i got bored trying to understand it. Possibly the size limitation u mentioned maybe the problem, (although this image has 69kb size compared to 55kb of others that work), so i just passed the file path to the intent and loaded that into my full screen activity. Anyhow, thanks for the help! – chris.b Apr 25 '15 at 17:08

0 Answers0