如何将同一个对象一个活动传递给另外两个不同的活动
问题描述:
我想将同一个对象从一个活动传递给另外两个不同的活动。我为两者使用相同的代码,但对其中一个不起作用。我使用这些代码发送位图。如何将同一个对象一个活动传递给另外两个不同的活动
Intent nIntent = new Intent();
nIntent.setClass(getApplicationContext(), tag.class);
nIntent.putExtra("bitmap",thumbnail);
startActivity(nIntent);
Intent mIntent = new Intent();
mIntent.setClass(getApplicationContext(), PictureView.class);
mIntent.putExtra("bitmap",thumbnail);
startActivity(mIntent);
我在其他活动中使用这些代码。
imgView = (ImageView) findViewById(R.id.img_preview);
Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("bitmap");
imgView.setImageBitmap(bitmap);
但是其中一个它不会出现在imageview上。
答
使用一个Parcelable之前把它放进额外。我确保你有正确的道路,你的形象:
Drawable thumbnail = R.drawable.thumbnail;
Intent mIntent = new Intent();
Bundle b = new Bundle();
b.putParcelable("bitmap", thumbnail);
mIntent.putExtra(b);
mIntent.setClass(getApplicationContext(), PictureView.class);
startActivity(mIntent);
,并在mIntent活动使用:
Bundle extras = getIntent().getExtras();
if(extras != null){
Drawable image = b.getParcelable("bitmap");
}
是“标记”的类名?哪一个工作,哪个不工作? –
哪一个不能解决这两个问题? –
我会猜测'标记'类不会扩展活动。 – Blundell