How to send an object containing drawable objects

2019-05-18 00:17发布

I've gone through this: How to send an object from one Android Activity to another using Intents?

But i'm facing problem in sending images in the object to the other activity.

Please help.

2条回答
男人必须洒脱
2楼-- · 2019-05-18 00:52

Convert your Drawable to Bitmap and send it to Another Activity.

Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

To send,

intent.putExtra("Bitmap", bitmap);

To Fetch,

Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
查看更多
等我变得足够好
3楼-- · 2019-05-18 00:56

Well you can't really send images with intents since you can attach as extras to intents only Serializable objects. But you can store images (in memory in different structures (like HashMaps, using hashmap will give you some speed optimization for searching that image)) and send notification to other activity to read from hasmap. You can add the key for the image in hashmap as string in extras attached to intent. Or you can just cache the image and send it's name/path via intents :)

Hope this helps :)

查看更多
登录 后发表回答