How to pass custom object in Bundle?

Sheehan Alam picture Sheehan Alam · Apr 26, 2011 · Viewed 79.9k times · Source

I am trying to pass my own custom object into a bundle:

Bundle b = new Bundle();
                STMessage message = (STMessage)a.getAdapter().getItem(position);
                b.putObject("message",message);

I get the error:

The method putObject(String, Object) is undefined for the type Bundle

Answer

Ryan Reeves picture Ryan Reeves · Apr 26, 2011

One way is to have your custom object implement the Parcelable interface and use Bundle.putParcelable/Bundle.getParcelable