0

I have developed one Android application.

The app is performing displayed list view using xml parsing.

I have used below code. The text data is pass from one activity to next activity successfully but the image doesn't pass from one activity to another activity.

How can I pass image from one activity to the next activity in Android application?

This is first activity:

String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String duration = ((TextView) view.findViewById(R.id.duration)).getText().toString();
String artist = ((TextView) view.findViewById(R.id.artist)).getText().toString();
String image = ((ImageView) view.findViewById(R.id.list_image)).getImageMatrix().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_DURATION, duration);
in.putExtra(KEY_ARTIST, artist);
in.putExtra(KEY_THUMB_URL, image);
startActivity(in);

This is next activity:

Intent in = getIntent();

// Get XML values from previous intent
String title = in.getStringExtra(KEY_TITLE);
String duration = in.getStringExtra(KEY_DURATION);
String artist = in.getStringExtra(KEY_ARTIST);
Bitmap bitmap =(Bitmap) in.getParcelableExtra(KEY_THUMB_URL);
// Displaying all values on the screen
TextView lblName = (TextView) findViewById(R.id.name_label);
TextView lblCost = (TextView) findViewById(R.id.cost_label);
TextView lblDesc = (TextView) findViewById(R.id.description_label);
ImageView image = (ImageView)findViewById(R.id.image_label);
image.setImageBitmap(bitmap); 
lblName.setText(title);
lblCost.setText(duration);
lblDesc.setText(artist);

EDIT:

I have changed the first activity like below code:

String image = ((ImageView) view.findViewById(R.id.list_image)).getImageMatrix().toString();
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_THUMB_URL, image);

I have changed the second activity like below:

static final String KEY_THUMB_URL = "Image";
String Image = in.getStringExtra(KEY_THUMB_URL);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());
ImageView thumb = (ImageView) findViewById(R.id.image_label);
imageLoader.DisplayImage(Image, thumb);

After I have to run the app means I am getting empty image only.

Michaël
  • 3,679
  • 7
  • 39
  • 64
  • how are the images prepared for the listview? if all the data in your listview is already ordered on the device, perhaps you could just pass the position to your activity then act on that. – mango Nov 28 '12 at 04:47
  • you can see this post http://stackoverflow.com/questions/6463243/android-get-the-image-source-name-of-an-imageview-to-display-on-a-textview for passing images between Activity – ρяσѕρєя K Nov 28 '12 at 04:59
  • @user1855914 Please see my answer may be it will solve your problem. – Dipak Keshariya Nov 28 '12 at 06:15

2 Answers2

0

For passing Image between acitivities first convert your image into bitmap then pass that bitmap to next activity using THIS.

Community
  • 1
  • 1
Hardik Joshi
  • 9,477
  • 12
  • 61
  • 113
0

Bitmap cannot be passed through the intent directly instead you will have to convert the bitmap into byte array and then transfer the byte array through intent and in called activity convert the byte array into bitmap.

Bitmap bitmap = BitmapFactory.decodeResource(getResources(),"Image ID");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes); 

Then passing the image

            intent.putExtra("imagepass", bytes.toByteArray());
             startActivity(intent);

Then on called activity

    Bundle extras = getIntent().getExtras();
    byte[] byteArray = extras.getByteArray("imagepass");
    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

    ImageView iv=(ImageView) findViewById(R.id.imgvw2);
    iv.setImageBitmap(bmp);
Aryan
  • 67
  • 1
  • 6