How can I pass a Bitmap object from one activity to another

michael picture michael · Mar 17, 2010 · Viewed 136.9k times · Source

In my activity, I create a Bitmap object and then I need to launch another Activity, How can I pass this Bitmap object from the sub-activity (the one which is going to be launched)?

Answer

Erich Douglass picture Erich Douglass · Mar 17, 2010

Bitmap implements Parcelable, so you could always pass it with the intent:

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);

and retrieve it on the other end:

Intent intent = getIntent(); 
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");