Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MyObjects Parcelable class
- import java.util.ArrayList;
- import android.os.Parcel;
- import android.os.Parcelable;
- public class MyObjects implements Parcelable {
- private int age;
- private String name;
- private ArrayList<String> address;
- public MyObjects(String name, int age, ArrayList<String> address) {
- this.name = name;
- this.age = age;
- this.address = address;
- }
- public MyObjects(Parcel source) {
- age = source.readInt();
- name = source.readString();
- address = source.createStringArrayList();
- }
- @Override
- public int describeContents() {
- return 0;
- }
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(age);
- dest.writeString(name);
- dest.writeStringList(address);
- }
- public int getAge() {
- return age;
- }
- public String getName() {
- return name;
- }
- public ArrayList<String> getAddress() {
- if (!(address == null))
- return address;
- else
- return new ArrayList<String>();
- }
- public static final Creator<MyObjects> CREATOR = new Creator<MyObjects>() {
- @Override
- public MyObjects[] newArray(int size) {
- return new MyObjects[size];
- }
- @Override
- public MyObjects createFromParcel(Parcel source) {
- return new MyObjects(source);
- }
- };
- }
- MyObjects mObjects = new MyObjects("name","age","Address array here");
- //Passing MyOjects instance
- Intent mIntent = new Intent(FromActivity.this, ToActivity.class);
- mIntent.putExtra("UniqueKey", mObjects);
- startActivity(mIntent);
- //Getting MyObjects instance
- Intent mIntent = getIntent();
- MyObjects workorder = (MyObjects) mIntent.getParcelable("UniqueKey");
- //You can pass Arraylist of Parceble obect as below
- //Array of MyObjects
- ArrayList<MyObjects> mUsers;
- //Passing MyOjects instance
- Intent mIntent = new Intent(FromActivity.this, ToActivity.class);
- mIntent.putParcelableArrayListExtra("UniqueKey", mUsers);
- startActivity(mIntent);
- //Getting MyObjects instance
- Intent mIntent = getIntent();
- ArrayList<MyObjects> mUsers = mIntent.getParcelableArrayList("UniqueKey");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement