Created
August 29, 2012 19:31
-
-
Save eric-taix/3517619 to your computer and use it in GitHub Desktop.
@parcelable solution 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EActivity(R.layout.main) | |
public class FirstActivity extends Activity { | |
@ItemClick | |
public void myListItemClicked(MyItem clickedItem) { | |
Intent intent = new Intent(app, ClipsListActivity_.class); | |
MyBean bean = new MyBean(); | |
intent.putExtra("my_bean", new MyBean_(bean)); | |
startActivity(intent); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Parceable | |
public class MyBean { | |
public int aInt = 4; | |
public long aLong = 67; | |
public String aString = "A string"; | |
public Date aDate = new Date(2012, 8, 29); | |
public MyChild child = new MyChild(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyBean_ extends MyBean implements Parcelable { | |
private MyBean bean; | |
public MyBean_(MyBean bean) { | |
this.bean = bean; | |
} | |
public MyBean_(Parcel in) { | |
bean = new MyBean(); | |
aInt = in.readInt(); | |
aLong = in.readLong(); | |
aString = in.readString(); | |
aDate = new Date(in.readLong()); | |
child = (MyChild_)in.readParcelable(this.getClass().getClassLoader()); | |
} | |
@Override | |
public int describeContents() { | |
return 0; | |
} | |
@Override | |
public void writeToParcel(Parcel dest, int flags) { | |
dest.writeInt(bean.aInt); | |
dest.writeLong(bean.aLong); | |
dest.writeString(bean.aString); | |
dest.writeLong(bean.aDate.getTime()); | |
dest.writeParcelable(new MyChild_(bean.child), flags); | |
} | |
public static final Parcelable.Creator<MyBean_> CREATOR = new Parcelable.Creator<MyBean_>() { | |
public MyBean_ createFromParcel(Parcel in) { | |
return new MyBean_(in); | |
} | |
public MyBean_[] newArray(int size) { | |
return new MyBean_[size]; | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Parcelable | |
public class MyChild { | |
public byte[] aByteArray = { 0x01, 0x05, 0X02, 0x03, 0x04 }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyChild_ extends MyChild implements Parcelable { | |
private MyChild bean; | |
public MyChild_(MyChild bean) { | |
this.bean = bean; | |
} | |
public MyChild_(Parcel in) { | |
aByteArray = in.createByteArray(); | |
} | |
@Override | |
public int describeContents() { | |
return 0; | |
} | |
@Override | |
public void writeToParcel(Parcel dest, int flags) { | |
dest.writeByteArray(bean.aByteArray); | |
} | |
public static final Parcelable.Creator<MyChild_> CREATOR = new Parcelable.Creator<MyChild_>() { | |
public MyChild_ createFromParcel(Parcel in) { | |
return new MyChild_(in); | |
} | |
public MyChild_[] newArray(int size) { | |
return new MyChild_[size]; | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EFragment(R.layout.clips_layout) | |
public class SecondFragment extends Fragment { | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
Bundle bundle = getActivity().getIntent().getExtras(); | |
if (bundle != null) { | |
MyBean bean = (MyBean) bundle.get("my_bean"); | |
System.out.println(bean); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment