Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
swdev:android:start [2018/05/04 06:34] smayr [Explicit Intent] |
swdev:android:start [2018/05/22 14:15] (current) smayr [Resources] |
||
---|---|---|---|
Line 5: | Line 5: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
* [[https:// | * [[https:// | ||
Line 223: | Line 224: | ||
</ | </ | ||
+ | A parcelable extra must be of a type supporting parcelable. | ||
+ | <code java> | ||
+ | package com.acme.myapp; | ||
+ | |||
+ | import android.os.Parcel; | ||
+ | import android.os.Parcelable; | ||
+ | |||
+ | public class Team implements Parcelable | ||
+ | { | ||
+ | public long id = 0; | ||
+ | public String name = ""; | ||
+ | public String number = ""; | ||
+ | public int ranking = 0; | ||
+ | |||
+ | // Default constructor | ||
+ | Team() | ||
+ | { | ||
+ | |||
+ | } | ||
+ | |||
+ | // In constructor, | ||
+ | // Important: Read them in the same sequence in which they were written in Parcel. | ||
+ | public Team(Parcel in) { | ||
+ | id = in.readLong(); | ||
+ | name = in.readString(); | ||
+ | number = in.readString(); | ||
+ | ranking = in.readInt(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public int describeContents() { | ||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | // Write member variables in Parcel. | ||
+ | // Write in any order. Not required to write all members in Parcel. | ||
+ | @Override | ||
+ | public void writeToParcel(Parcel dest, int flags) { | ||
+ | // Write data in any order | ||
+ | dest.writeLong(id); | ||
+ | dest.writeString(name); | ||
+ | dest.writeString(number); | ||
+ | dest.writeInt(ranking); | ||
+ | } | ||
+ | |||
+ | // De-serialize the object | ||
+ | public static final Parcelable.Creator< | ||
+ | public Team createFromParcel(Parcel in) { | ||
+ | return new Team(in); | ||
+ | } | ||
+ | |||
+ | public Team[] newArray(int size) { | ||
+ | return new Team[size]; | ||
+ | } | ||
+ | }; | ||
+ | } | ||
+ | </ | ||
=== Intent Examples === | === Intent Examples === | ||
For example, in the '' | For example, in the '' |