In android there are two ways to achieve send and receive objects bebtween Activities:
they must:
- Serializable (Implment object as Serializable)
or
- Parcelable (Implement object as Parcelable)
you will need to implement Parcelabel
and add the following methods to the class
a constructor with a parcel as parameter
public Telnet(Parcel in) {
readFromParcel(in);
}
override the writeToParcel method
@Override
public void writeToParcel(Parcel dest, int flags) {
// write each field into the parcel. When we read from parcel, they
// will come back in the same order
dest.writeString(strVar); // to write your string variables
dest.writeInt(intVar); // to write your int variables
}
a method for read from Parcel
private void readFromParcel(Parcel in) {
strVar= in.readString();
intVar= in.readInt();
}
a parcel creator
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
public Telnet createFromParcel(Parcel in) {
return new Telnet(in);
}
public Telnet[] newArray(int size) {
return new Telnet[size];
}
};
@Override
public int describeContents() {
return 0;
}
then your Telnet class is ready to be transfer to another activities.
Now use it:
in the main act do:
Telnet obj = new Telnet();
// Set values etc.
Intent i = new Intent(this, MyActivity.class);
i.putExtra("your.package.Telnet", obj);
startActivity(i);
and in the second activity do:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
Telnet obj =
b.getParcelable("your.package.Telnet");
}