1

I am trying to pass values to a new activity but cannot read the values from the new activity.

here is my code,

Intent myIntent = new Intent(Photo2Activity.this, MainActivity.class);

myIntent.putExtra("image1", image1);
myIntent.putExtra("image2", image2);
myIntent.putExtra("image3", image3);

myIntent.putExtra("konteyner_no", _txt_konteyner_id.getText().toString());
myIntent.putExtra("mahalle", _txt_mahalle.getText().toString());
myIntent.putExtra("sokak", _txt_sokak.getText().toString());

myIntent.putExtra("konteyner_temizmi", _check_konteyner_temizmi.isChecked());
myIntent.putExtra("yaninda_cop_varmi", _check_yaninda_cop_varmi.isChecked());
myIntent.putExtra("aralarinda_cop_varmi", _check_aralarinda_cop_vardi.isChecked());
myIntent.putExtra("zamansiz_cop_varmi", _check_zamansiz_cop_vardi.isChecked());
myIntent.putExtra("cop_obekleri_vardi", _check_cop_obekleri_vardi.isChecked());

myIntent.putExtra("note", _txt_note.getText().toString());

startActivity(myIntent);

how do I read them from the new activity(MainActivity)?

Arif YILMAZ
  • 5,754
  • 26
  • 104
  • 189
  • if its primitive types that you want to pass then check this link http://stackoverflow.com/questions/15859445/how-do-you-pass-a-string-from-one-activity-to-another/15859488#15859488. Are you passing images?? – Raghunandan May 15 '13 at 10:14
  • I have 3 bitmaps that I am sending – Arif YILMAZ May 15 '13 at 10:14
  • for bitmap http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another – bendyna May 15 '13 at 10:17

1 Answers1

2

Convert Bitmap to Byte Array:-

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();

Pass byte array into intent:-

Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("picture", byteArray);
startActivity(intent);

Get Byte Array from Bundle and Convert into Bitmap Image:-

Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(bmp);

Passing primitive types check the link below

How do you pass a string from one activity to another?

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • I need to pass those images and others to a webservice. is it better to send it to as bytearray? – Arif YILMAZ May 15 '13 at 10:20
  • you are title says passing bitmaps(values in your title) between activities. does not mention about webservice. the answer is for passing bitmaps between activities. You should use http post request to send image to server – Raghunandan May 15 '13 at 10:25