0

我正在尝试将值传递给新活动,但无法从新活动中读取值。

这是我的代码,

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);

如何从新活动(MainActivity)中读取它们?

4

1 回答 1

2

将位图转换为字节数组:-

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

将字节数组传递给意图:-

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

从 Bundle 中获取字节数组并转换为位图图像:-

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);

传递原始类型检查下面的链接

你如何将字符串从一个活动传递到另一个活动?

于 2013-05-15T10:17:13.053 回答