开发者

how to pass the same object one activity to another two different activities

I want to pass the same object from one activity to another two different activities. I use same code for both, but it didn't work for one of them. I use these codes to send bitmap.

Intent nIntent = new Intent();
nIntent.setClass(getApplicationContext(), tag.class);
nIntent.putExtra("bitmap",thumbnail);
startActivity(nIntent);

Intent mIntent = new Intent();
mIntent.setClass(getApplicationContext(), PictureView.class);开发者_C百科
mIntent.putExtra("bitmap",thumbnail);
startActivity(mIntent);

I use these codes in the other activities.

imgView = (ImageView) findViewById(R.id.img_preview);                           
Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("bitmap");
imgView.setImageBitmap(bitmap);

But one of them it doesn't appear on the imageview.


Use a Parcelable before putting it into extras. I make sure you have the right path to your image:

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

and in the mIntent Activity use this:

Bundle extras = getIntent().getExtras();
if(extras != null){
    Drawable image = b.getParcelable("bitmap");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜