How to send an object containing drawable objects from one android activity to another using intents?

你离开我真会死。 提交于 2019-12-05 22:11:53

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!