我想點擊Activity 1
中的一個按鈕並顯示圖片Activity 2
,但它不起作用。如何在Android中的活動之間傳遞圖像?
活動1:
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
// Bundle bundle = new Bundle();
Drawable drawable=img1.getDrawable();
Bitmap bitmap= ((BitmapDrawable)drawable).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
intent.putExtra("picture", b);
// String ten = edt.getText().toString();
// bundle.putString("tenkh", ten);
// intent.putExtras(bundle);
startActivity(intent);
活性2:
ImageView image = (ImageView) findViewById(R.id.img2);
TextView txtTen= (TextView) findViewById(R.id.tv1);
Intent goiIntent=getIntent();
Bundle extras = goiIntent.getExtras();
byte[] b = extras.getByteArray("picture");
Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
image.setImageBitmap(bmp);
的[我如何通過Android上的活動之間的數據?(可能的複製http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on- android) – Tim