NRahman
NRahman

Reputation: 2757

I want to Passing a image from Drawable from one activity to Another via Intent?

I am using this part of code to send the image...

public void onClick(View v) {

                Intent goto_membersdealsdetails = new Intent(
                        "com.abc.cd.FE");

                goto_membersdealsdetails.putExtra("valueq", R.drawable.app_icon);


                v.getContext().startActivity(goto_membersdealsdetails);

And to get the image i am using this sort of code...

   imag_link = getIntent().getStringExtra("valueq");

   Toast.makeText(getApplicationContext(), imag_link, Toast.LENGTH_LONG)
                    .show();

Its Toast is providing a blank toast....

I want to set the image to a certain imageview....Suggestion please

Upvotes: 0

Views: 2976

Answers (2)

Tarun
Tarun

Reputation: 13808

You are passing an int value in intent. so call

imag_link = getIntent().getIntExtra("valueq", value);

Upvotes: 1

Sunil Kumar
Sunil Kumar

Reputation: 7092

you can pass byte array and get bytearray and then make bitmap

 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);     
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); 
    byte[] b = baos.toByteArray();

    Intent intent = new Intent(this, ActivityB.class);
    intent.putExtra("picture", b);
    startActivity(intent);

In Activity B you receive intent with byte array (decoded picture) and apply it as source to ImageView:

Bundle extras = getIntent().getExtras();
byte[] b = extras.getByteArray("picture");

Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

Upvotes: 2

Related Questions