Hello Everyone,
I am trying to pass SampleParcelable class object say sampleObj from my ClassA (current) activity to ClassB (a new one), but when i log the objects value, the object's value which i am creating in ClassA is totally different from what i get in ClassB.
ClassA :-
public class ClassA extends Activity
{
private SampleParcelable sampleObj;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sampleObj = new SampleParcelable();
Log.d("Actual Reference Value", "\t" + sampleObj);
Intent terminateActivity = new Intent( ClassA.this, ClassB.class );
terminateActivity.putExtra("SampleValue", sampleObj);
SampleParcelable readbackCi = terminateActivity.getParcelableExtra("SampleValue");
Log.d("Retrieved Value", "\n\n\t" + readbackCi);
}
}
ClassB :-
public class ClassB extends Activity
{
private SampleParcelable newSampleObj;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try {
Intent intentObj = getIntent();
Log.d("Intent Value", "intent: " + intentObj.toString());
Log.d("Extra Values", "extras: " + intentObj.getExtras());
newSampleObj = (SampleParcelable) intentObj.getParcelableExtra("SampleValue");
Log.d("New Value", " " + newSampleObj.toString());
} catch (Exception e) {
Log.d("Exception in main", e.toString());
}
}
}
SampleParcelable :-
public class SampleParcelable implements Parcelable
{
public SampleParcelable(Parcel in) {
in.readParcelable(SampleParcelable.class.getClassLoader());
}
public SampleParcelable() {
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
// TODO Auto-generated method stub
}
public static final Parcelable.Creator<SampleParcelable> CREATOR = new Parcelable.Creator<SampleParcelable>() {
public SampleParcelable createFromParcel(Parcel in) {
return new SampleParcelable(in);
}
public SampleParcelable[] newArray(int size) {
return new SampleParcelable[size];
}
};
}
After debugging I guess, I know 1 reason why my object values are different, because when retrieving object in ClassB using getParcelableExtra() at that time my SampleParcelable class createFromParcel method is called which internally creates a new object. May be i m wrong.
I am not getting any solution for this, i just want same object in my new class so that i can access some values using that object which were set in my ClassA activity.
Thanks in advance