0

I've created one Listview and when I click on list view, I want to send that row image details at Detail view Activity (another activity).

For this I tried below code but I'm getting below Exception

java.lang.Integer cannot be cast to android.os.Parcelable

FirstActivity:-

 // Listen for ListView Item Click

        view.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                // Send single item click data to SingleItemView Class
                Intent intent = new Intent(mContext, SingleItemView.class);
                intent.putExtra("imageId",(worldpopulationlist.get(position).getImageId()));
                mContext.startActivity(intent);
             }
        });
    }

SecondActivity:-

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.singleitemview);


        // Retrieve data from MainActivity on item click event
        Intent i = getIntent();
        // Get the results of imageView
        Bitmap bmp = (Bitmap) i.getParcelableExtra("imageId");
        srcimage = (ImageView)findViewById(R.id.imageId);
        srcimage.setImageBitmap(bmp);
    }
j_4321
  • 15,431
  • 3
  • 34
  • 61
AbhiRam
  • 2,033
  • 7
  • 41
  • 94

2 Answers2

0

Try with this.Because you pass a integer value in your FirstActivity

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.singleitemview);

        Intent i = getIntent();
        int yourImageId =  i.getIntExtra("imageId"); <----

    }
Kristiyan Varbanov
  • 2,439
  • 2
  • 17
  • 37
-1

There are two ways to do so:

  1. get the bytes from bitmap of image and post it as byte array in intent receive it and reconvert it in bitmap but activity transition becomes slow in this case;

  2. store image somewhere retrieve it in other activity then delete it then.

JJ86
  • 5,055
  • 2
  • 35
  • 64