Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're just passing objects around then <a href="http://developer.android.com/reference/android/os/Parcelable.html" rel="noreferrer">Parcelable</a> was designed for this. It requires a little more effort to use than using Java's native serialization, but it's way faster (and I mean way, <strong><em>WAY</em></strong> faster).</p> <p>From the docs, a simple example for how to implement is:</p> <pre><code>// simple class that just has one member property as an example public class MyParcelable implements Parcelable { private int mData; /* everything below here is for implementing Parcelable */ // 99.9% of the time you can just ignore this @Override public int describeContents() { return 0; } // write your object's data to the passed-in Parcel @Override public void writeToParcel(Parcel out, int flags) { out.writeInt(mData); } // this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods public static final Parcelable.Creator&lt;MyParcelable&gt; CREATOR = new Parcelable.Creator&lt;MyParcelable&gt;() { public MyParcelable createFromParcel(Parcel in) { return new MyParcelable(in); } public MyParcelable[] newArray(int size) { return new MyParcelable[size]; } }; // example constructor that takes a Parcel and gives you an object populated with it's values private MyParcelable(Parcel in) { mData = in.readInt(); } } </code></pre> <p>Observe that in the case you have more than one field to retrieve from a given Parcel, you must do this in the same order you put them in (that is, in a FIFO approach).</p> <p>Once you have your objects implement <code>Parcelable</code> it's just a matter of putting them into your <a href="http://developer.android.com/reference/android/content/Intent.html" rel="noreferrer">Intents</a> with <a href="http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20android.os.Parcelable%29" rel="noreferrer">putExtra()</a>:</p> <pre><code>Intent i = new Intent(); i.putExtra("name_of_extra", myParcelableObject); </code></pre> <p>Then you can pull them back out with <a href="http://developer.android.com/reference/android/content/Intent.html#getParcelableExtra%28java.lang.String%29" rel="noreferrer">getParcelableExtra()</a>:</p> <pre><code>Intent i = getIntent(); MyParcelable myParcelableObject = (MyParcelable) i.getParcelableExtra("name_of_extra"); </code></pre> <p>If your Object Class implements Parcelable and Serializable then make sure you do cast to one of the following:</p> <pre><code>i.putExtra("parcelable_extra", (Parcelable) myParcelableObject); i.putExtra("serializable_extra", (Serializable) myParcelableObject); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload